The tag has no usage guidance.

learn more… | top users | synonyms

5
votes
5answers
340 views

BASH: how to pass a default argument if no arguments after the first were passed

I have a bash script with a case statement in it: case "$1" in bash) docker exec -it $(docker-compose ps -q web) /bin/bash ;; shell) docker exec -it $(docker-compose ...
4
votes
1answer
56 views

How to remove a positional parameter from $@

Basically, I want to "pluck out" the first occurrence of -inf from the parameter list. (The remaining parameters will be passed along to a different command.) The script I have has the following ...
0
votes
1answer
17 views

get command line agrument by variable in shell script

I want to get the arg of a command from a var that has the index in it of the arg that I want. Something like this # command in terminal, `foo -r -f value_wanted` index="3" var=$"$index" echo $var ...
1
vote
0answers
51 views

How do C programs pass whitespace arguments to the libc system(3) calls? [migrated]

When a C program calls system() to run a Unix command, I know it's possible to pass arguments to the command, and according to a StackOverflow answer (from a very high-rep user), the system() call ...
1
vote
1answer
52 views

get first CLI argument after the options in shell scipt

I have a script I class like so gitploy up -t 2.0.0 test_repo. I pull out the "action" up right away, then I need to be able to get the test_repo before I process the options. I don't want to lose ...
1
vote
1answer
42 views

How to prevent bash from transforming arguments?

I am trying to use an argument of the script to find other files. The problem is that when i give the script the argument x.* in the command line, it is transformed into x.sh. Any ideas how i can get ...
10
votes
4answers
813 views

Why doesn't echo called as /bin/sh -c echo foo output anything?

For example, while this works: $ echo foo foo This doesn't: $ /bin/sh -c echo foo Whereas this does: $ /bin/sh -c 'echo foo; echo bar' foo bar Is there an explanation?
0
votes
0answers
20 views

Match all arguments (like $@) except last? [duplicate]

I was only able to find solutions for matching all but $1. Like shift for example. Like: command argument1 argument2 argument3 argument4 I would match argument1, argument2 and argument3 but not ...
3
votes
2answers
81 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 -: ...
1
vote
1answer
36 views

globbing and $# [closed]

Suppose my shell script gets 3 arguments: ./myscript dir1 material dir2 I need $# to report the count of items globbed with dir1/* and not the count of my script's original 3 arguments. Do you ...
2
votes
2answers
75 views

How to specify multiple input arguments stored in a file to a command?

I would like to convert several webpages into a pdf file, by: wkhtmltopdf http://think-like-a-git.net/sections/about-this-site.html ...
3
votes
2answers
65 views

Content of /proc/<PID>/cmdline file depends on script shebang?

I have a bash script named test.sh which I start with startproc. In case I use #!/usr/bin/env bash shebang in test.sh, the /proc/<PID>/cmdline file looks following: SERVER:~ # cat ...
0
votes
2answers
76 views

In a folder with many files how to do rm on lots of them [duplicate]

I just experimented a bit in linux and ended up getting very many files in one and the same folder. Now when I try to do rm -f folder/*.png I get -bash: /bin/rm: Argument list too long ...
0
votes
0answers
17 views

Difference between “$@” and “$*” when passing arguments to bash function [duplicate]

I'm having hard time understanding difference between $@ and $* when passing them to functions. Here is example: function a { echo "-$1-" "-$2-" "-$3-"; } function b { a "$@" } function c ...
1
vote
2answers
80 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 ...
0
votes
1answer
36 views

picocom -b 115200 - Why do you need to specify the baudrate?

I have an intel galileo board and if I try to connect to it from my laptop with: picocom /dev/ttyUSB0 I get just akward characters like: Terminal ready � ...
2
votes
5answers
39 views

What determines how program arguments needs to be separated?

I noticed that kill utility is able to accept arguments separated both by a space character and a newline: $ sleep 120 & sleep 240 & [1] 75341 [2] 75342 $ /bin/kill $(echo "75341 75342") [1]- ...
0
votes
2answers
81 views

While loop for bash scripting to read either stdin or arguments

I'm playing around with the accepted answer from this thread: Bash script that reads filenames from a pipe or from command line args? When I use the below script, efetch ...
3
votes
1answer
114 views

How to determine program success when running a sequence of similar tasks?

I am writing a series of CLI tools that share the same parent command, similar to programs like git. program verb OPTIONS One of the action verbs, install, is designed to git clone as many ...
1
vote
1answer
24 views

Alias gedit to accept an argument

This alias works in UNIX and in Redhat. It does not work in Fedora alias te 'gedit "\!*" &' Usage: te myfile.cpp It opens gedit with myfile.cpp in the edit window and runs in the ...
1
vote
2answers
36 views

pipe as arguments

I'm trying to use the output of a command as arguments: The command: /home/alexandre/dropbox.py exclude add ls | grep -v photos I have to add a list of files, for example: ...
1
vote
2answers
128 views

Call one shell script with another

If I have a program that multiplies the user-supplied value with 10, how do I write another bash script that has arguments passed to it and takes these arguments and collects the output of the other ...
1
vote
2answers
34 views

What does the `set — $args` line do here, and why does it behave differently between Zsh and Bash?

In the manpage for the version of getopt that comes with Mac OSX, an example is given that uses the construction args=$(getopt optstring $*); set -- $args. What does set -- $args do here? ...
0
votes
2answers
55 views

Passing contents of a file on the command line [duplicate]

I'm trying to figure out how I can send arguments (which are contents in a file) on the command line as parameters to a cpp function. I am NOT trying to send it through stdin. I have a function named ...
1
vote
1answer
50 views

Indirectly expand variables in shell

I need to indirectly reference a variable in the bash shell. I basically want to what you can do in make by writing $($(var)). I have tried using ${$var} which would be the most straight forward ...
3
votes
1answer
39 views

functions arguments

I am having trouble with what should be a simple bash script. I have a bash script that works perfectly: function convert_to () x_max=2038 y_max=1146 x_marg=100 y_marg=30 x_grid=150 y_grid=150 if ...
0
votes
1answer
48 views

Expand parameter in quotes in zsh

(Not sure the title is adequate, at least I tried my best…) I want to pass function arguments to zsh’s emulate to evaluate a command in bash emulation: $ .bash() { emulate bash -c "$*" } $ .bash ...
3
votes
2answers
165 views

What's the `name` argument to `sh` for/do?

Taken from FreeBSD's man page on sh (because its the most convenient online, target platform is Debian if it matters): SH(1) FreeBSD General Commands Manual SH(1) NAME sh -- ...
-1
votes
1answer
68 views

script with no arguments should echo a message, but it doesn't [closed]

I'm questioning why my script still does not run the condition when no argument is provided. I think it might be the ordering of my if statements but I'm not sure. Any advice? It doesn't seem to be a ...
1
vote
2answers
48 views

Jump to specific flag in help/man file

Let's say I'm curious about what a specific flag -T means for a command ls? Is there a way to jump straight to that using man ls...? or, and this is a slightly different question because it's not ...
15
votes
4answers
1k views

How can the standard input of one program be passed as an arg to another?

Let's say a program exists, which takes two arguments; input file and output file. What if I don't wish to save this output file to disk, but rather pass it straight to stdin of another program. Is ...
1
vote
2answers
43 views

Else not Executing

In my script, I transform data to a more readable format. But I am having an issue. If no arguments are typed, just the script, I want it to come back "Please enter a filename" which I have done. But ...
1
vote
0answers
45 views

Can't get bare-bone simple bash function to work [closed]

I have some tmux scripts in a directory, and I'm trying to make a script to make it easier to call them. Function is below tms() { ~/linux/scripts/tmux-scripts/$1 } This is in my bashrc, I then ...
1
vote
1answer
86 views

sh - Using Arguments in .profile functions

I want to use an argument in the function I created in my .profile file. I want to ask for input if no argument is given, otherwise set a variable to $1. When I check $1 to see if it is empty, I ...
0
votes
1answer
182 views

Bash if statement not working properly [closed]

I have a bash statement to test a command line argument. If the argument passed to the script is "clean", then the script removes all .o files. Otherwise, it builds a program. However, not matter what ...
3
votes
4answers
181 views

Provide strings stored in a file as a list of arguments to a command?

I install a list of URLs in a text file named myurls: http://www.examples.com/1 http://www.examples.com/2 http://www.examples.com/3 How shall I pass these URLs to wkhtmltopdf as inputs? The direct ...
0
votes
1answer
278 views

How many files can rm delete at once? [duplicate]

One of my friends wanted to have more logs in the /var/log/ directory, and after some time of using the system, he tried to access the folder and list it, but instead he got the following error: ...
3
votes
4answers
123 views

How do I get the value of a named option of an already running process in Linux?

I run the following command. ps -e -o args | grep destiny | grep UNIX I receive the following output. /path/to/destiny -r -m UNIX -t TCP -p 1501 What command can I use the get the value of the ...
0
votes
1answer
34 views

How does “command < filename.txt” look when passing filename into a command

I've got a scenario where I have command < filename.txt so I can pass the contents of filename.txt and use it in command. But say I want to take the contents out of the file and just use them in ...
0
votes
2answers
162 views

Help with passing parameters to a file and fetching the credentials

I have developed a shell script which takes schema id and password as parameter to login into database using sqlplus,runs a query and mails the result. Below is the code snippet: #!/bin/sh #Two ...
1
vote
2answers
371 views

How to extract unknown arguments within a shell script?

I have a shell script that accepts a variety of options, some with arguments, some without, some short, some long. It should handle some of these options itself and pass on the rest it does not know ...
0
votes
0answers
66 views

Passing argument in tcl proc

I have a tcl proc as follow: proc foo {a {b 300} {check FALSE} {c 100}} { //doing something here } Can I pass the value to c argument while still using default values for b and check arguments ...
0
votes
2answers
147 views

bash execute command for X arguments at a time

I have a list of files stored in txt file. ./test7 ./test4 ./test1 ./test5 ./test6 ./test10 ./test8 ./test2 ./test9 ./test3 I want to run a command on all those files but I want to sleep 1 second ...
2
votes
1answer
103 views

Bash completion - How to get filename completion for suboptions

I have a function which can take main arguments and then sub-arguments. Some of these sub-arguments are filenames. The current completion code I have is as follows. _scm() { local cur prev opts ...
1
vote
0answers
26 views

What Does the Output of “--help” Mean? [duplicate]

When using the --help option of a terminal program, a lot of output is produced. It usually starts with Usage: and then a bunch of things and brackets and parentheses. My question is, what doe the ...
1
vote
3answers
229 views

Shell expansion for arguments?

For example: mkdir ~/{1,2,3} Creates directories ~/1, ~/2, and ~/3. It equates to: mkdir ~/1 mkdir ~/2 mrdir ~/3 But, using the same syntax in the case of CMD < argument > : brew {install, ...
2
votes
1answer
120 views

Order between options and operands?

When using a utility program, we may specify options (and their option arguments) and/or operands. In most cases (in the sense of conforming to some standard (POSIX?)) does the order between ...
2
votes
4answers
165 views

input file stream to command

How is it possible to send a file stream to this command instead of a file? /usr/local/bin/wkhtmltopdf --title "$SUBJECT" -q $SOURCEFILE $OUTPUTFILE The file stream is from a string in PHP.
1
vote
2answers
59 views

Do I need “| xargs -n 1” to get around xargs' -I side-effect?

I was suprised to discover this: $ echo 1 2 3 4 5 | xargs -n 1 echo 1 2 3 4 5 $ echo 1 2 3 4 5 | xargs -n 1 -I FOO echo FOO 1 2 3 4 5 That is, using the -I flag has this side effect: Also, ...
1
vote
1answer
101 views

Using parameters in a script

I usually use the find command to automatically copy certain multimedia files from directory A to directory B. I use the following command: for f in `find ./ -name "*.mkv" -mtime -24h`; do cp $f ...