Linked Questions

9 votes
1 answer
5k views

Is there a way to expand a variable into multiple arguments without globbing in bash? [duplicate]

I would like to define an expression for find which includes a wildcard in a -name subexpression: find_expression="-type f -name *.csv -mtime +14" And then use it in a couple of places ...
Tom Anderson's user avatar
  • 1,058
2 votes
2 answers
9k views

Concatenate strings in bash while adding double quotes [duplicate]

I have the following bash script: set -ex X="bash -c" Y="ls -al" I want to execute (notice the double quotes): bash -c "ls -al" The following does not work: C=$X\ $Y $C This gives as output + X='...
dwjbosman's user avatar
  • 479
1 vote
2 answers
2k 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"' $...
igorepst's user avatar
  • 143
0 votes
1 answer
5k views

curl inside bash function giving "option unknown" for --data [duplicate]

I'm trying to pass --data-raw options to a curl inside bash function, but I get option unknown error. function api_call () { local data="$5" echo $(curl -L -X $1 "https://...
Kurse's user avatar
  • 1
2 votes
2 answers
2k views

Removing single quotes from double-quoted variable element in array and run a command [duplicate]

I have a script where I dinamically change the arguments which must be passed to a command (mkvpropedit in this case). Consider the example script below: #!/bin/bash LANG_NAME="eng lish" ...
virtualdj's user avatar
  • 177
3 votes
1 answer
3k 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 ...
Dmitry's user avatar
  • 31
1 vote
2 answers
2k views

Combine two command defined as String in variable and run as one [duplicate]

Can I join two commands defined as String and run as one. E.g. var="ls -alt" var2="| grep usersfile" var3="| grep usersfolder" Following example for joining commands does not work. a. '{$var & $...
m19v's user avatar
  • 153
0 votes
1 answer
1k 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: #!/...
nyholku's user avatar
  • 101
1 vote
2 answers
984 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 ...
exiting's user avatar
  • 15
3 votes
1 answer
427 views

Problem with single quote in Bash [duplicate]

I have a sh script for initializing dzen2, and I want to use Source Code Pro font to use there. Here's the code... param="-p -dock -fn 'Source Code Pro-10'" # the generated_output function ...
manungsa's user avatar
  • 137
0 votes
1 answer
2k views

Prevent splitting command line argument at spaces when running in bash script [duplicate]

I'm trying to run a command in a bash variable, like this: cmd="python -m mymodule 'argument 123 456' argument2=32 argument3=234" $cmd It looks like it is splitting the command line ...
user1506145's user avatar
1 vote
1 answer
2k views

Multiple commands in variable? [duplicate]

Is it possible to execute multiple commands stored in a variable? Singe command works fine variable="echo HELLO" $variable HELLO I would like to have something like this variable="echo ...
user avatar
1 vote
1 answer
317 views

rsync pass multiple exclude from $@ [duplicate]

I'm trying to make a wrapper around my rsync command to reuse code. I need to pass the source folder, the target folder and then any number of excluded directories. Here is what I have with the logs; ...
Bancarel Valentin's user avatar
0 votes
2 answers
653 views

Passing options to any linux programs from variables [duplicate]

Desired code: echo "$var" | sort -t/ -k 1,1n -k2,2n -k3,3n Case scenario: options to sort arr dynamically created based on condition and stored in variables. How can i pass them. option='-...
user avatar
0 votes
1 answer
682 views

Trying to use sed within eval statement? [duplicate]

Trying to use sed within eval statement? #!/bin/bash declare COMMAND="sudo sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config" theResponse=$(${COMMAND} 2&...
Dachshund Digital's user avatar

15 30 50 per page
1
2 3 4 5
12