7
votes
2answers
377 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 ...
4
votes
2answers
243 views

Add arguments to bash -c

Let 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 ...
1
vote
1answer
57 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 ...
0
votes
1answer
220 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 ...
3
votes
2answers
202 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 ...
0
votes
2answers
263 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 ...
3
votes
2answers
1k 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. ...
2
votes
2answers
602 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 following ...
6
votes
2answers
302 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 ...
3
votes
2answers
413 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 ...
12
votes
7answers
792 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 ...