Questions tagged [parameter]
211 questions
143
votes
3 answers
How to check if there are no parameters provided to a command?
How do you check if $* is empty? In other words, how to check if there were no arguments provided to a command?
well actually
- 3,045
- 5
- 20
- 11
140
votes
6 answers
How to pass parameters to an alias?
For bash script, I can use "$@" to access arguments. What's the equivalent when I use an alias?
prosseek
- 8,418
- 16
- 47
- 43
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
72
votes
4 answers
Transform an array into arguments of a command?
I have an array of "options" of a command.
my_array=(option1 option2 option3)
I want to call this command in a bash script, using the values from array as options. So, command $(some magic here with my_array) "$1" becomes:
command -option1 -option2…
Somebody still uses you MS-DOS
- 4,725
- 10
- 36
- 44
69
votes
4 answers
bash iterate file list, except when empty
I thought this would be simple - but it is proving more complex than I expected.
I want to iterate through all the files of a particular type in a directory, so I write this:
#!/bin/bash
for fname in *.zip ; do
echo current file is…
symcbean
- 5,008
- 2
- 25
- 37
47
votes
1 answer
How do ${0##*/} and ${0%/*} work?
I'm quite confused about the following regular expressions I found in a shell script:
${0##*/}
${0%/*}
How do they work?
user785099
- 701
- 2
- 8
- 11
43
votes
4 answers
Bash: slice of positional parameters
How can I get a slice of $@ in Bash without first having to copy all positional parameters to another array like this?
argv=( "$@" )
echo "${argv[@]:2}";
n.r.
- 2,173
- 3
- 18
- 30
35
votes
2 answers
What does `:-` mean in a shell script
I saw this in the end of an awesome shell script but I can't understand the logic here because I think it's being short-handed for a longer command.
spark ${@:-`cat`}
This apears at the end of this script. Any ideas?
+ Marks for some one who…
whoami
- 3,750
- 7
- 27
- 26
35
votes
3 answers
Correct behavior of EXIT and ERR traps when using `set -eu`
I'm observing some weird behavior when using set -e (errexit), set -u (nounset) along with ERR and EXIT traps. They seem related, so putting them into one question seems reasonable.
1) set -u does not trigger ERR traps
Code:
#!/bin/bash
trap 'echo…
dvdgsng
- 403
- 1
- 4
- 10
24
votes
2 answers
command line terminology: what are these parts of a command called?
At the command line I often use "simple" commands like
mv foo/bar baz/bar
but I don't know what to call all the parts of this:
┌1┐ ┌──2───┐
git checkout master
│ └──────3──────┘
└───────4─────────┘
I (think I) know that 1 is a command and 2's an…
theonlygusti
- 797
- 5
- 17
23
votes
1 answer
Execute command supplied by function parameters
I'm trying to create a function method in a bash script that executes a command which is supplied to the method by the paramters.
Meaning somethings like this:
special_execute()
{
# Some code
# Here's the point where the command gets…
BrainStone
- 3,534
- 12
- 32
- 53
22
votes
3 answers
Pass an option to a makefile
Makefile
my_test:
ifdef $(toto)
@echo 'toto is defined'
else
@echo 'no toto around'
endif
Expected behavior
$ make my_test
no toto around
$ make my_test toto
toto is defined
Current behavior
$ make my_test
no toto around
$ make…
smarber
- 1,181
- 2
- 12
- 25
21
votes
2 answers
How to pass parameters to function in a bash script?
I'd like to write a function that I can call from a script with many different variables. For some reasons I'm having a lot of trouble doing this. Examples I've read always just use a global variable but that wouldn't make my code much more readable…
user181822
- 213
- 1
- 2
- 5
21
votes
2 answers
Optional parameters in bash function
I have a function for quickly making a new SVN branch which looks like so
function svcp() { svn copy "repoaddress/branch/$1.0.x" "repoaddress/branch/dev/$2" -m "dev branch for $2"; }
Which I use to quickly make a new branch without having to look…
Madden
- 335
- 1
- 2
- 7
20
votes
2 answers
GRUB2 and kernel vga= parameter
According to the documentation, use of the vga= kernel parameter is deprecated as of GRUB2. The fact that some newer kernels don't seem to support it anymore on certain adapters is of no concern as the graphics card I have is seven to eight years…
0xC0000022L
- 16,189
- 24
- 102
- 168