Skip to main content

All Questions

Tagged with
3 votes
1 answer
247 views

tcsh: Handle spaces in arguments when passing on to another command

I wrote a script that needs to call a command and pass on arguments. My script has its own parameters but some need to be passed through. This fails when arguments to my script have spaces in them. ...
Ned64's user avatar
  • 8,924
0 votes
2 answers
884 views

How to properly parse a quoted arg-list string in a shell script?

Summary How to convert a single string a "b" 'c d' $'e\nf' into separate arguments, respecting quotes and preserving whitespaces and newlines? Question I'm trying to read and process the ...
Christian's user avatar
  • 101
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,056
1 vote
1 answer
616 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
1 answer
542 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
  • 213
0 votes
1 answer
45 views

Script Integer getting prefixed with "

I am running a jar file using a very basic shell script (I literally just need this to run on startup of a NAS). However, I am getting some rather unexpected behavior: Script looks like this: java -...
Nico-Ben de Villiers's user avatar
4 votes
4 answers
3k 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
2 votes
1 answer
81 views

Generating quoted command arguments

I'm working with a HTTP API that demands a very particular set of signed headers + JSON body. And I really want to cURL it for debugging and sanity in general. So, I've written a small script that, ...
Morten Siebuhr's user avatar
2 votes
2 answers
1k views

Keeping quotes passed to a perl wrapper script

I'm writing a small perl wrapper to setup environment variables, etc., then invoke a command by the same name. ./foo.pl -a one -b two -c "1 2 3" -d done When I output @ARGV, the "" around 1 2 3 have ...
alfinator's user avatar
0 votes
2 answers
126 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
3 votes
1 answer
6k views

Passing arguments with spaces and quotes to a script (without quoting everything)

The following works great on the command-line: $ ffmpeg -i input.m4a -metadata 'title=Spaces and $pecial char'\''s' output.m4a How do I parameterize this command and use it in a script/function? I ...
Leftium's user avatar
  • 173
1 vote
1 answer
824 views

How to pipe netcat's output? Problems with xargs and quotes

I'm trying to pipe whatever nc receives with this: nc -l 20000 | xargs /root/test ...and it works fine, except when xargs receives quoted arguments - it splits them as if they were separate... ...
user224371's user avatar
5 votes
2 answers
2k views

How to re-write this function to avoid argument injection

I have a function in my .bashrc file that allows me to run a script on a remote server with arguments via ssh. Currently, the function contains: function runMyScript { if [ $1 = "s3" ] then ...
cpd's user avatar
  • 153
9 votes
4 answers
3k 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
498 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
10k 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
16k 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,087
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
  • 411
1 vote
2 answers
578 views

Can't use argument in bash date calculation script

The following bash script won't work. I need to calculate the date depending on the number of days since 14th Oct 1582, where the argument will be the number of days. d="$1" date -d '14 Oct 1582 + "$...
Jacques MALAPRADE's user avatar
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
52 votes
3 answers
75k 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
483 views

How to enclose a quoted variable in quotes

I want to call: ./mjpg_streamer -i "./input_uvc.so -r 320x240" -o "./output_http.so -w ./www" from a C program, running system(). The problem is that I have to enclose shell command in quotes, which ...
dempap's user avatar
  • 725
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 ...
user72685's user avatar
  • 333
3 votes
2 answers
531 views

Command substitution interpreting spaces within quotes as argument separators

I'd like an alias that additionally appends itself to ~/.bashrc, e.g. function tailias { $(echo "alias $1='${*:2}'" | tee -a ~/.bashrc) } I'm using tee to split the command to ~/.bashrc while ...
Andrew Cheong's user avatar
0 votes
2 answers
3k views

Making md5sum understand file names with spaces

I need to use md5sum in Python by using pipe to calculate checksum for a bunch of .mp3 files... is there a command which ignore whitespaces in filenames on the command line of md5sum program? For ...
Reloader's user avatar
  • 103
14 votes
4 answers
19k views

How to prevent command injection through command options?

I have an wrapper application where I need to let the user specify custom options to pass to a simulator. However, I want to make sure the user doesn't inject other commands through the user options. ...
Victor L's user avatar
  • 409
12 votes
2 answers
23k views

Pass arguments to function exactly as-is

I have the following function: bar() { echo $1:$2; } I am calling this function from another function, foo. foo itself is called as follows: foo "This is" a test I want to get the ...
Konrad Rudolph's user avatar
7 votes
3 answers
2k views

Bash : command line with optional arguments

I'm running this kind of code: #!/usr/bin/env bash set -u exclude1='--exclude=/path/*' exclude2='--exclude=/path with spaces/*' exclude3='' # any 'exclude' can be empty tar -czf backup.tgz "$...
Gregory MOUSSAT's user avatar
5 votes
2 answers
4k views

Bash: passing braces as arguments to bash function

I love using the following pattern for searching in files: grep --color=auto -iRnHr --include={*.js,*.html,} --exclude-dir={release,dev,} "span" . I'd like, however, to have this one wrapped into a ...
oleq's user avatar
  • 383
148 votes
11 answers
55k views

What is the difference between $* and $@?

Consider the following code: foo () { echo $* } bar () { echo $@ } foo 1 2 3 4 bar 1 2 3 4 It outputs: 1 2 3 4 1 2 3 4 I am using Ksh88, but I am interested in other common ...
rahmu's user avatar
  • 20.1k