An argument is usually defined as the actual value passed to a function, procedure, or command line program.
Questions tagged [arguments]
512 questions
266
votes
15 answers
Passing named arguments to shell scripts
Is there any easy way to pass (receive) named parameters to a shell script?
For example,
my_script -p_out '/some/path' -arg_1 '5'
And inside my_script.sh receive them as:
# I believe this notation does not work, but is there anything close to…
Amelio Vazquez-Reina
- 40,169
- 77
- 197
- 294
222
votes
4 answers
What is the purpose of using shift in shell scripts?
I have came across this script:
#! /bin/bash
if (( $# < 3 ));…
Patryk
- 13,556
- 22
- 53
- 61
221
votes
7 answers
Pass the output of previous command to next as an argument
I've a command that outputs data to stdout (command1 -p=aaa -v=bbb -i=4).
The output line can have the following value:
rate (10%) - name: value - 10Kbps
I want to grep that output in order to store that 'rate' (I guess pipe will be useful…
Paul
- 2,211
- 2
- 12
- 3
143
votes
11 answers
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 shells as well. If you happen to know any particularity for…
rahmu
- 19,673
- 28
- 87
- 128
124
votes
9 answers
Solving "mv: Argument list too long"?
I have a folder with more than a million files that needs sorting, but I can't really do anything because mv outputs this message all the time
-bash: /bin/mv: Argument list too long
I'm using this command to move extension-less files:
mv --…
Dominique
- 5,155
- 8
- 26
- 29
118
votes
11 answers
Why does argv include the program name?
Typical Unix/Linux programs accept the command line inputs as an argument count (int argc) and an argument vector (char *argv[]). The first element of argv is the program name - followed by the actual arguments.
Why is the program name passed to…
Shrikant Giridhar
- 1,267
- 2
- 11
- 13
102
votes
11 answers
How do I echo just 1 column of output from ls command?
Lets say when I do ls command the output is:
file1 file2 file3 file4
Is it possible to display only a certain column of output, in this case file2? I have tried the following with no success:
echo ls | $2
Basically all I want to do is echo only…
John
- 3,459
- 13
- 29
- 25
86
votes
8 answers
Multiple arguments in shebang
I am wondering whether there is a general way of passing multiple options to an executable via the shebang line (#!).
I use NixOS, and the first part of the shebang in any script I write is usually /usr/bin/env. The problem I encounter then is that…
Rastapopoulos
- 1,569
- 1
- 10
- 21
80
votes
5 answers
Argument list too long for ls
I get the following error when trying to ls *.txt | wc -l a directory that contains many files:
-bash: /bin/ls: Argument list too long
Does the threshold of this "Argument list" dependent on distro or computer's spec? Usually, I'd pipe the result…
user19016
75
votes
3 answers
What defines the maximum size for a command single argument?
I was under the impression that the maximum length of a single argument was not the problem here so much as the total size of the overall argument array plus the size of the environment, which is limited to ARG_MAX. Thus I thought that something…
Graeme
- 33,607
- 8
- 85
- 110
74
votes
3 answers
How does curl protect a password from appearing in ps output?
I noticed some time ago that usernames and passwords given to curl as command line arguments don't appear in ps output (although of course they may appear in your bash history).
They likewise don't appear in /proc/PID/cmdline.
(The length of the…
Wildcard
- 35,316
- 26
- 130
- 258
52
votes
1 answer
When and how was the double-dash (--) introduced as an end of options delimiter in Unix/Linux?
I don't think the shell/utilities in historical Unix nor in something as "recent" as 4.4BSD supported using a double-dash(or two consecutive hyphens) as an end of options delimiter. With FreeBSD, you can see for instance a note introduced in the rm…
user44370
51
votes
3 answers
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 multiple arguments seem to work with kill:
sudo kill…
Tomáš Zato
- 1,734
- 7
- 24
- 38
50
votes
3 answers
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
# | pass all unprocessed arguments…
Slartibartfast
- 635
- 1
- 5
- 7
47
votes
2 answers
How to pass argument with spaces to a shell script function?
I'm trying to pass multiple argument to a function, but one of them is consist of two words and I want shell function to deal with it as one arg:
args=("$@")
function(){
echo ${args[0]}
echo ${args[1]}
echo ${args[2]}
}
when I call this command…
user78050
- 1,045
- 2
- 11
- 16