Skip to main content

All Questions

Tagged with
5 votes
3 answers
1k views

Find exec sh: Shell variable not getting passed to subshell

Here is a simplified code that prints the name of Directory if it contains a Filename with same name as the parent directory and .md extension. FIND(){ find . -type d -exec sh -c ' for d ...
Porcupine's user avatar
  • 2,146
1 vote
1 answer
748 views

problem escaping quotes in script

I'm constructing a command line for use with the 'mogrify' tool [part of imagemagick]. the finalised command line looks something like this : mogrify -stroke yellow -draw 'line 0,0 0,319' -draw 'line ...
david furst's user avatar
0 votes
2 answers
598 views

Why do these rsync filter args fail in bash when passed in array?

Why does this rsync command work when I give it literally but not when I create it from variables? Here are the variables - first the options I'm passing to rysnc, as an array: $ echo "${options[@]}"...
markling's user avatar
  • 231
4 votes
4 answers
4k views

Correctly quote array that is being passed indirectly via another command

I need to pass an array of filenames to a command, preserving proper quoting. So far, so good. Unfortunately the command is actually a sub-command that is, in turn, invoked by another command. ...
Konrad Rudolph's user avatar
0 votes
2 answers
145 views

Bash : Give builded array to function as a list of argument?

I have this issue with borgbackup, but because the reaction is the same, I will use rsync in my example. I want to build an array of arguments by adding a prefix to each, and then give that array to ...
Vlycop Doo's user avatar
2 votes
0 answers
85 views

Bash: Special variables $@ vs. $* in For Loop [duplicate]

Using $@ instead of $* would preserve quoting. Consider the following script: #!/bin/bash # Test.sh for arg in $@ do echo "I found the argument $arg" done ./Test.sh "One Two Three" I reach the ...
sci9's user avatar
  • 527
9 votes
4 answers
4k views

Can a shell script prints its argument, quoted as you would write them on the shell prompt?

In a shell script, my understanding is that "$@" expands to the script arguments, quoting them as needed. For instance this forwards the script arguments to gcc: gcc -fPIC "$@" When using the bash ...
Alex Jasmin's user avatar
2 votes
1 answer
4k views

Passing a git command as an argument

I'm trying to automate some tedious parts of a student job I'm working on. Basically, the goal is to clone a bunch of git repositories (which I already have working), then run the same git checkout ...
Trevor Muraro's user avatar
0 votes
2 answers
511 views

bash script function argument problem [duplicate]

Not sure why this is producing error. This is a test code emulating my real code. I want to write a wrapper for find and want to allow for any argument, so I'm wrapping each arg in single quotes. #...
codechimp's user avatar
  • 207
3 votes
2 answers
11k views

Passing paths with spaces as arguments

I am having difficulty in passing some string variables having spaces in them as arguments to a program. For debugging and showing the arguments being passed, I created a demo Python script -: #####...
Anmol Singh Jaggi's user avatar
21 votes
3 answers
17k views

How does 'find -exec' pass file names with spaces?

If I have a directory containing some files whose names have spaces, e.g. $ ls -1 dir1 file 1 file 2 file 3 I can successfully copy all of them to another directory like this: $ find dir1 -mindepth ...
EmmaV's user avatar
  • 4,215
1 vote
2 answers
2k views

UNC Argument in bash scipt

I want to create a bash script with a "pure" UNC (i.e. I do not want to escape the backslashes literally) as an argument, i.e. something like: ./foo \\my\share\is\here However, as is natural, the ...
trikelef's user avatar
  • 460
18 votes
2 answers
12k views

Bash string concatenation used to build parameter list

Given this piece of bash: PARMS='-rvu' PARMS+=" --delete --exclude='.git'" echo $PARMS rsync ${PARMS} . ${TARGET} The echo shows the PARMS string as expected, no error is displayed, but rsync ...
neuviemeporte's user avatar
54 votes
3 answers
78k views

Add arguments to 'bash -c'

Let's say that I want to run a command through Bash like this: /bin/bash -c "ls -l" According to Bash man page, I could also run it like this: # don't process arguments after this one #...
Slartibartfast's user avatar
1 vote
1 answer
2k views

Bash Script : Passing a variable to a bash script that contains quotes, single quotes. etc [closed]

lets assume this is the string: 'a',"b" it contains both single and double quotes. how would you pass this to a bash script as a single string ? this is the bash script: #!/bin/bash echo $1 it ...
user72685's user avatar
  • 333

15 30 50 per page