1
vote
2answers
32 views

Pass arguments to a command run by another user

I have a bash script that is supposed to take some arguments and then run in a different user: test.sh #!/bin/bash sudo su user2 <<'EOF' echo $1 EOF However it prints blank: $ ./test.sh ...
7
votes
2answers
221 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
3answers
102 views

Passing arguments from one command into the next

I'm trying to write a script to unify two separate commands I run by hand into a single bash script I can then cron. The first command is a simple find on files with a certain name and size find ...
0
votes
1answer
37 views

Must pass urls in quotes

I'm trying pass a URL to mpv for it to play it as a network stream. This can be done in bash with the following syntax: $ mpv http://myvideosite.com However, zsh wants to evaluate the URL as ...
4
votes
2answers
134 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
49 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 ...
7
votes
3answers
762 views

Why do some commands not read from their standard input?

I wonder what when we should use pipeline and when we shouldn't. Say for instance, to kill certain process which handling pdf files, the following will not work by using pipeline: ps aux | grep pdf ...
1
vote
1answer
48 views

Kill all queued jobs

I need to kill all the queued and running jobs on my ID. I have tried at -l | awk '{print $1}'| at -r {} But I keep getting {} does not exist Which leads me to believe that I am parsing ...
0
votes
1answer
161 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 ...
2
votes
3answers
95 views

Can I chain pgrep with kill?

I have noticed that | is used to send results of first command to the another. I would like to kill all processes that match a name. This is what pgrep normally does: $ pgrep name 5089 5105 And ...
0
votes
1answer
142 views

Pipe output from one command to another command's non standard input [duplicate]

I would like to do something similar to the following: which someapplciation | cd outputfrompreviouscommand The command which provides a directory and I would like to be able to make that output my ...
3
votes
2answers
2k views

Solving “mv: Argument list too long”?

I have a folder with more than a million files that needs sorting, but I cant really do anything because mv outputs this message all the time -bash: /bin/mv: Argument list too long I'm using this ...
6
votes
1answer
134 views

How to specify additional parameters for GNU sort's --compress-program option?

sort --compress-program=/bin/gzip works fine, but how can I pass options down to the compression programm (e.g. --best or --fast)? sort --compress-program=/bin/gzip\ --best failes with the error ...
8
votes
3answers
337 views

How to execute a command repeatedly with different arguments?

I'm on Ubuntu. I copied some arguments (separated by newline) and I can use xsel to print them out like this $ xsel arg1 arg2 arg3 arg4 ... Now, I want to use each of these arguments for another ...
1
vote
1answer
111 views

Using sed output in another script or command

How can I use the output of sed in another script? For example (this doesn't work): sed -n "$COUNTER",1p /domains.csv | wget or sed -n "$COUNTER",1p /domains.csv > /myScript.sh As far as I ...
3
votes
3answers
459 views

Correctly parse arguments in script behaving like a shell called through SSH

I have a server with a very limited used whom I want to be able to run two very specific (and custom) instructions through SSH. In order to do that, I have set the shell for that limited user to be a ...
15
votes
2answers
519 views

How can I stream data to a program that expects to read data from a file that is given as a argument?

I have a huge gzipped file and I want a program (4s-import in this case) to read it. It takes a lot of time to first unzip the file and then call the program with the path to the file as an argument. ...
4
votes
2answers
279 views

Why do I need the double dash before argument passed to sh by xargs -I for it to work properly?

Sorry for the mouthful title. Here is the command in question find . -name "*.txt" | xargs -Ifile sh -c 'echo $(basename $1) ' -- file So without the double dash the file is not passed to sh and ...
8
votes
5answers
3k views

cp with a single argument containing wildcards [duplicate]

If I have the following 2 files and 1 folder: someuser@computer:~/Desktop/test$ ls -l total 340 -rw-r--r-- 1 someuser someuser 45082 ago 5 09:56 file1.pdf -rw-r--r-- 1 someuser someuser 291836 ago ...
2
votes
2answers
117 views

Is it possible to create a “file” that can be used by any process without actually saving the file on disk?

Suppose I do a grep that gives me a lot of results. I want to use the output of grep and pass it to a command that takes a filename as it's first argument. For example - myCommand filename.txt I ...
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. ...
3
votes
2answers
2k views

how to loop through arguments in a bash script

I would like to write a bash script with unknown amount of arguments. How can I walk through these arguments and do something with them? A wrong attempt would look like this: #!/bin/bash for i in ...
4
votes
2answers
994 views

How to pass arguments to bash shell script when executing that command with at?

I have a shell script that accepts an argument and uses that in the script. So to run the script I type /path/to/script argument The problem is when trying to setup that file to run using the at ...
-1
votes
1answer
103 views

Why do many CLI apps take a single “--” argument? [duplicate]

Possible Duplicate: What does “--” (double-dash) mean? There are many command line tools that take a single "--" argument. For example: gem install mysql -- ...
1
vote
1answer
97 views

Redirection doesn't show up as an argument to a sourced script

My problem is that I can't print to the screen when I write a bash script . myBashScript.sh < text.txt In myBashScript.sh I just print out echo $2 But instead of printing "text.txt", it ...
12
votes
7answers
736 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 ...