Questions tagged [arguments]
An argument is usually defined as the actual value passed to a function, procedure, or command line program.
102 questions
153
votes
11
answers
58k
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 shells ...
80
votes
3
answers
100k
views
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 ...
239
votes
7
answers
673k
views
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 ...
11
votes
2
answers
30k
views
CP: max source files number arguments for copy utility
Consider that there are countless number of files under /src/
cp /src/* /dst/
How many files cp will successfully process?
114
votes
8
answers
58k
views
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 /...
136
votes
10
answers
219k
views
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 ...
15
votes
3
answers
5k
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 ...
89
votes
5
answers
169k
views
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 ...
75
votes
3
answers
10k
views
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 ...
46
votes
7
answers
4k
views
Is `-` used only with cd?
cd - can switch between current dir and previous dir.
It seems that I have seen - used as arguments to other commands before, though I don't remember if - means the same as with cd.
I found that - ...
33
votes
2
answers
34k
views
What's the difference between STDIN and arguments passed to command?
I could use the either form to execute the cat method:
cat file_name
cat < file_name
The result is the same
Then I want to execute man in the format of stdin
man < file_name
While file_name ...
27
votes
4
answers
13k
views
Why do some commands not read from their standard input?
I wonder 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 | awk '{...
22
votes
2
answers
44k
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 $...
10
votes
2
answers
7k
views
UNIX-, BSD-, GNU-options in Linux's ps command. Where are they from?
In the manual for the ps command on Ubuntu there is this text:
This version of ps accepts several kinds of options:
1 UNIX options, which may be grouped and must be preceded by a
dash.
...
9
votes
1
answer
4k
views
Executing `sh -c` script through SSH (passing arguments safely and sanely)
I suddenly realized I don't know how to execute things over SSH.
I tried to do
$ ssh user@server sh -c 'echo "hello"'
but it outputs nothing, or rather, it outputs an empty line. If the command ...