Linked Questions
15 questions linked to/from Using shell variables for command options
2
votes
2
answers
48k
views
Bash flags based on if statements [duplicate]
I am calling a bash script that has a number of flags in the following manner:
/home/username/myscript -a -b 76
So to illustrate, the -a flag does something in myscript and the -b flag sets some ...
1
vote
0
answers
473
views
How to pass a pattern to grep as a variable? [duplicate]
I use the following command, as part of a script, to backup from my W10 machine with WSL to a Debian box:
rsync -PaSh --stats --delete -e 'ssh -p XXXX -i ~/keys/key' /mnt/c/Users/User/Desktop/ user@...
1
vote
0
answers
42
views
How to properly quote variables, which are then no longer considered if omitted [duplicate]
I am a bit at a loss right now as to why a script of mine does not work as I perceived it.
Since id3v2 is a bit complex to use, I tried to simplify its uses by writing a script around it. The parts ...
213
votes
6
answers
341k
views
How can we run a command stored in a variable?
$ ls -l /tmp/test/my\ dir/
total 0
I was wondering why the following ways to run the above command fail or succeed?
$ abc='ls -l "/tmp/test/my dir"'
$ $abc
ls: cannot access '"/tmp/test/my': No such ...
282
votes
3
answers
57k
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 ...
40
votes
3
answers
28k
views
Conditionally pass params to a script
I have a script running on Linux that accepts some parameters.
I would like to do something like:
if [[ $CONDITION == "true" ]]; then
script param1 --param2
else
script param1
fi
I would ...
51
votes
2
answers
13k
views
Are quotes needed for local variable assignment?
Can I safely omit quotes on the right side of a local assignment?
function foo {
local myvar=${bar}
stuff()
}
I'm mainly interested in bash, but any info on corner cases in other shells are ...
6
votes
2
answers
5k
views
Why does bash add single quotes to unquoted failed pathname expansions in a command before executing it?
I was exploring the tracing of commands using set -x (set +x to unset) in bash:
Print a trace of simple commands, for commands, case commands, select
commands, and arithmetic for commands and ...
3
votes
3
answers
10k
views
bash - Single quotes being added to double quotes [closed]
I'm writing a script to run a given program on a simulator while changing the argument supplied and I'm having a problem where bash keeps inserting single ticks around the double quotes that causes ...
1
vote
2
answers
5k
views
command substitution - cat file inserts quotes
In bash, given these files:
$ cat noquotes.txt
s/a/b/g
$ cat quotes.txt
"s/a/b/g"
Why does
$ echo "aaa" | sed -e $(cat noquotes.txt)
bbb
succeed, but
$ echo "aaa" | sed -e $(cat quotes.txt)
sed: 1: ...
0
votes
1
answer
2k
views
find files, exclude directories
I would like to compose a string of command line arguments in a variable, then use those to execute a command. I show a simplified example below. It's is a script called "listfiles." It ...
1
vote
2
answers
780
views
Asterisk/Double Quote Failing to Excecute
Sory I'm new to shellscripting. I have a variable that contains an option related to find command.
TYPE=("-type f")
NAME=("-name \"*log*\"")
I try put those variable ...
-1
votes
1
answer
328
views
Unexpected quotes in zsh trace
I've got a third party script that receives command line arguments in this form:
$ ./script.sh --params a=123 b=456
There is a file xyz.txt with this contents:
c=3
d=4
I'm trying to use its contents ...
0
votes
1
answer
87
views
How to integrate multiple inline `if` variable checks into `configure` flag selection
I'm compiling Nginx from source on Debian 12 in Bash. I'd like to select the TLS vendor (e.g. LibreSSL, OpenSSL) via a preflight variable ($nginx_tls_vendor). An example configure command without the ...
0
votes
1
answer
118
views
Possibilities to Append the Command in Variable
I have a variable that contains a find command
LST_FILE=$(find . -type f \( -name -o '*xml*' -o -name -o '*log*' \) -mmin 180)
Is it possible to append the command ? I mean like this
LST_FILE+=$(-...