Linked Questions
151 questions linked to/from How do I parse command line arguments in Bash?
64 votes
4 answers
285k views
How can I pass a file argument to my bash script using a Terminal command in Linux? [duplicate]
So my question is how can I pass a file argument to my bash script using a Terminal command in Linux? At the moment I'm trying to make a program in bash that can take a file argument from the Terminal ...
81 votes
2 answers
65k views
Command line arguments in Bash [duplicate]
I want to write a bash script which takes different arguments. It should be used like normal linux console programs: my_bash_script -p 2 -l 5 -t 20 So the value 2 should be saved in a variable called ...
14 votes
5 answers
12k views
bash script parameters [duplicate]
I need to write a bash script, and would like it to parse unordered parameters of the format: scriptname --param1 <string> --param2 <string> --param3 <date> Is there a simple way to ...
7 votes
1 answer
36k views
How to pass two parameters or arguments in bash scripting [duplicate]
I am new to bash scripting and I need your support to solve this problem. I have a bash script "start.sh". I want to write a script with two arguments so that I could run the script in the following ...
4 votes
2 answers
10k views
Argument parsing in bash [duplicate]
I am new to bash. Need suggestion for the following problem. So I want to execute the script in this way ./myscript --bootstrap bootstrap.exe --vmmount ./vmmount --image /dev/sdb2 --target-exe ...
8 votes
1 answer
36k views
Argc and Argv in Bash [duplicate]
I written the following script which gets name of a file and then assemble and link the file. But it doesn't work. What is the problem with it? EXPECTED_ARGS=2 if [ $# -ne $EXPECTED_ARGS ] then ...
4 votes
1 answer
10k views
Giving a bash script the option to accept flags like a command [duplicate]
I'm writing a simple bash script and I would like it to accept parameters from the command line in any order. I've browsed around the web and wrote a simple function with a case statement in a while ...
2 votes
3 answers
8k views
Best way to parse arguments in bash script [duplicate]
So I've been reading around about getopts, getopt, etc. but I haven't found an exact solution to my problem. The basic idea of the usage of my script is: ./program [-u] [-s] [-d] <TEXT> Except ...
1 vote
1 answer
11k views
Bash : Elegant way for : case $1 in "parameter1" or "parameter2" [duplicate]
Here is my Bash script. Assuming that : 1) go.sh is the script to execute 2) the user will launch the script this way # ./go.sh -v file1.txt file2.txt or # ./go.sh --verbose file1.txt file2.txt 3)...
3 votes
1 answer
4k views
Check for flag passed to a Bash script and process value [duplicate]
I have a bash script in which I want to check if a flag with value was passed to it and then use the value in a variable. Something like this (pseudocode): file.sh -c 1.0.0 inside file.sh : #!/bin/...
1 vote
2 answers
5k views
How to process multiple command line arguments in Bash? [duplicate]
I am having problem allowing my script to take more than three arguments. My script will take commands like this, for example: ./myscript.sh -i -v -r filename so far if it only takes two arguments ...
7 votes
2 answers
2k views
In Bash, how can option flag values be stored in variables? [duplicate]
When writing Bash scripts, how can I obtain a value from the command-line when provided as part of option flags in the command line? For example in the following: ./script --value=myText --...
0 votes
1 answer
4k views
bash - command line arguments to script [duplicate]
hello all newbie here :D i am working on a project right now which involves a script that handles a *.dat file.The script runs under specific commands inputed by user my problem is that i cant ...
1 vote
3 answers
1k views
Bash arguments parse logic runs into infinite loop [duplicate]
I have a loop to parse command line arguments. Everything works fine if -d or -b argument has a parameter. But when I pass -d or -b without a parameter, the script gets into infinite loop. # Parse ...
0 votes
1 answer
2k views
Ways to provide list of parameters to options in shell scripts? [duplicate]
Basically I am making a script where I would like to give a list of parameters to some option, say -l, eg: usr@domain:$./somescript -l hi bye cry nigh The list specified to -l would be then stored ...