Linked Questions
338 questions linked to/from When is double-quoting necessary?
3 votes
1 answer
4k views
Is `echo $TEST` expanding an asterisk in the variable a bug? [duplicate]
Is this a Bash bug? $ mkdir test && cd test && echo "a" > "some.file" test$ echo '*' * test$ TEST=$(echo '*') test$ echo $TEST some.file Why is the second output the resolution of *...
3 votes
2 answers
6k views
Why do we double-quote a dollar sign evaluation in Bash? [duplicate]
I know single quotes will not evaluate what's inside, and double quotes will. I often see people quote-quote the dollar sign evaluation. Here are some examples: for i in "${indices[@]}"; do if [ "${a}"...
7 votes
2 answers
548 views
Do I need to quote command substitutions when assigning their output to a variable? [duplicate]
I tend to quote command substitutions as shown below even when assigning their output to a variable: var="$(command)" Is that actually needed though? When does it break? The accepted answer ...
2 votes
1 answer
6k views
bash $(printf "%s\n") does not create multiline [duplicate]
I created shell script, that logs into FTP server and renames some directories. I put FTP commands in multiline string like so # !/bin/sh ftp -inv $HOST << EOF user $USER $PASSWORD $COMMANDS ...
1 vote
1 answer
4k views
How to output comma separated values using IFS="," in shell [duplicate]
I have a small script, which does not give comma separated output when IFS is used, but IFS is mandatory as i need it to read many other value. The output of the below script is odi_server1 ...
1 vote
3 answers
961 views
Shell: only double quote on test -n/-z? [duplicate]
In case of test -e for example: VAR="<this is a file path: /path/to/file/or/dir" test -e $VAR && do_something || do_anotherthing Question: Should I use "$VAR" here?, here I don't like ...
3 votes
3 answers
1k views
Enclosing vs. not enclosing a variable's value in quotes in bash [duplicate]
When I do something like this: x="hi echo hello" or x='hi echo hello' Then x will contain the string hi echo hello. But when I don't use quotes: x=hi echo hello Then x will contain the string hi, ...
0 votes
2 answers
430 views
bash function does not show me date or cat arguments completely [duplicate]
I am writing a bash script for backup with log storage. I use my defined function as follows: logit () { echo " $1 $2 " >> /path/to/log } For logit 'Starting Backup' $(date +'%D ...
1 vote
1 answer
908 views
How can bash aliases be configured to handle spaces in directory names? [duplicate]
The alias below works well in zsh when spaces in directory names are \ escaped, but bash doesn't handle them properly. What changes would be required to make them work with bash properly. dum() { du ...
0 votes
1 answer
1k views
grep unexpected behavior when [0-9] pattern is given on ubuntu [duplicate]
When I use [0-9] pattern to search for all numbers in a file, whether to use or not use single/double quotes around the pattern produces different outputs. $ cat numbers this line has 3 this line has ...
0 votes
1 answer
543 views
Bash whois script calling local information with *? [duplicate]
I'm getting a very strange output from a script. Here is the line run in the terminal by itself: root@KaliTestBox:~/Desktop/dns1# echo $(whois 13.66.39.88 |head -n 40 |tail -n 28 |tr '\n' ' ') But ...
0 votes
0 answers
800 views
Shell scripting with brackets/parenthesis in folder names [duplicate]
I have a music library that I am trying to restore from backup. The original source library was on a QNAP NAS and I copied it over to a CentOS system without any problems. Now that I am trying to copy ...
3 votes
3 answers
253 views
What situations exist where Bash variables should not be double quoted? [duplicate]
I'm aware of several situations where it's unnecessary to use double quotes when expanding a variable in Bash, such as inside [[...]], or when used on the right hand side of a variable assignment. ...
0 votes
0 answers
592 views
How can I safely pass an argument containing '{{}}' to a bash script? [duplicate]
The following arguments are valid for docker command: docker ps -f"status=exited" --format 'table {{.Names}}' #output: # jovial_hellman # modest_blackwell So I have created this script docker-ps-...
0 votes
1 answer
438 views
How to escape echo? [duplicate]
Edit: I realized that this has nothing to do with $() it's just the result of using echo *. So I just need a way to escape with echo. I'm writing a script that checks what users don't have passwords ...