Linked Questions

1
vote
2answers
405 views

bash: [: missing `]' when the test stored in variable [duplicate]

Why this works: [ -r /tmp ] && echo "tt" >/tmp/taa cat taa tt But the following doesn't and how to fix that, preserving variable for reusability? COMD='[ -r /tmp ] && echo "tt"' $...
2
votes
2answers
269 views

Proper quote escaping/preserving in bash function [duplicate]

The following command with 2 parameters does what I need if I enter it in a terminal: mycommand 'string that includes many spaces and double quotes' 'another string that includes many spaces and ...
1
vote
2answers
58 views

Escaping spaces in dash [duplicate]

I want to do something like this. $ touch a\ b $ cmd=cat\ a\ b $ echo $cmd cat a b $cmd cat: a: No such file or directory cat: b: No such file or directory There are problems with the spaces in the ...
-1
votes
1answer
89 views

bash variable with quotes and percentage [duplicate]

I want to use a time command in a script and put it into a variable (I will have to use it for many commands) so than I can modify just the single variable. Simplified, this is how I tried it: ...
0
votes
0answers
90 views

find: paths must precede expression: in bash shell script [duplicate]

I can run this from the command line and it works: find /var/www/vhosts/foo/httpdocs/content/templates/ -name '*.plg' -print | xargs sed -i 's|mysql_|mysqli_|g' So I wrote the following sed.sh file ...
0
votes
1answer
54 views

Running command in a variable [duplicate]

It is often said that variables should be double quoted when used. In the following example I want to have the command echo "You can't see me" in a variable and run it in such a way that the output ...
0
votes
1answer
28 views

Construction an a command line bash script with spaces in path names [duplicate]

I need a simple script to call gcc but I've got a long list of libraries that I need to pass to it in a directory who's path has a space on it. In place of gcc for testing my script I've used: #!/...
0
votes
1answer
43 views

bash script with grep command not [duplicate]

I have this part of shell script : #!/bin/bash shopt -s extglob currentDate=$(date +%F) echo $currentDate command="grep $currentDate" gcs3='s3://gc-reporting-pud-production/splunk_printer_log_files' ...
0
votes
1answer
31 views

execute read command from var [duplicate]

I want to add "debug" optio to my script, for that I added a read commands in specific places in the code. Basically it look like this: #define it READ_USER_INPUT_IF_IN_DEBUG_MODE="read -p 'press any ...
1
vote
1answer
28 views

How to not split words [duplicate]

I have a list of commands in a file called cmds, one command per line. I want to grab the last command, set it in a variable last_command and run it later. with $last_command or "$last_command", or ...
0
votes
0answers
19 views

Bash String Concat issues [duplicate]

What seems to be going on here with the single quotes that are getting added to my concat'ed string? Something caused by the expansion of close($i)? for i in ${pid_fd_arr=[@]} do ...
0
votes
0answers
18 views

Add locale in variable for command [duplicate]

I'm trying to call a command from a variable in a script with a specific locale, example : $ myYTDL="LANG=C.UTF-8 youtube-dl --get-filename" but each time I try and call it in the script, I get : $ ...
264
votes
4answers
207k views

Why does my shell script choke on whitespace or other special characters?

Or, an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
199
votes
3answers
16k views

Security implications of forgetting to quote a variable in bash/POSIX shells

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
12
votes
2answers
8k views

Using shell variables for command options

In a Bash script, I'm trying to store the options I'm using for rsync in a separate variable. This works fine for simple options (like --recursive), but I'm running into problems with --exclude='.*': ...

15 30 50 per page