Linked Questions

0 votes
1 answer
4k views

How do I take optional parameters in my shell script. Command Line argument would be: ./abc.sh parm1 parm2 parm3 parm4 Here parm3 and parm4 are optional depending upon parm1(config) How to ...
Prashant Singh's user avatar
3 votes
1 answer
2k views

#====================script 5 -- ls reccurssive avec cd ======= #!/bin/bash exec 2>/dev/null # redirige stderr pour toute la suite # au cas ou le script est invoque sans argument $1 # n'existe pas, ...
user avatar
-3 votes
1 answer
387 views

It is not hard to set a default variable in bash. E.g: How to write a bash script that takes optional input arguments? But, these methods fail when using set -euxo pipefail. What methods are ...
Foobar's user avatar
  • 8,659
0 votes
1 answer
206 views

I made a simple script on WSL for windows 11 to mount my pen drive. The default option is to mount it from D:, and I can specify as an argument if the pen drive is in another place. The script is like ...
Pau's user avatar
  • 17
0 votes
2 answers
90 views

This is probably the worst question I've asked, I wasn't entirely sure how to formulate it and google results are best when the search is short and concise. So, I keep finding myself constantly ...
monolith937's user avatar
2 votes
1 answer
66 views

With the following bash function, how can I get the function allow $2 to be optional, defaulting its value when nothing is passed for that argument ? serputil () { local opstring="$1" ...
Dilna's user avatar
  • 465
1463 votes
14 answers
972k views

I have a whole bunch of tests on variables in a bash (3.00) shell script where if the variable is not set, then it assigns a default, e.g.: if [ -z "${VARIABLE}" ]; then FOO='default' else ...
Edward Q. Bridges's user avatar
64 votes
3 answers
40k views

I'd like to use getopts inside a function that I have defined in my .bash_profile. The idea is I'd like to pass in some flags to this function to alter its behavior. Here's the code: function t() { ...
Magnus's user avatar
  • 11.6k
15 votes
2 answers
25k views

So I have a question about get opts in bash. I want to get the value of the arguments if they are present but if they are not present to use a default value. So the script should take a directory ...
Greg's user avatar
  • 735
9 votes
3 answers
16k views

I'm trying make simple function for the useradd command and to quickly improve my poor shell programming skills. useradd -m -g [initial_group] -G [additional_groups] -s [login_shell] [username] Right ...
Dan's user avatar
  • 1,179
1 vote
1 answer
3k views

I have few npm scripts in my package.json as: "scripts": { "serve-india-local": "ng serve --project pro-india -c local", "serve-india-stag": "ng serve --project pro-india -c stag", "serve-india-...
Varun Sukheja's user avatar
-1 votes
1 answer
576 views

I have this shell script but I don't know why it doesn't work after passing parameters to it... Here it is #!/bin/bash # Check the argument type and change the directory depending on it. # Open with ...
Hussein Al-mosawi's user avatar
0 votes
1 answer
419 views

how to add output of user input? Use nano editor to create script from the scratch which will output the text provided as an argument, the name of the editor used to create the file and whether or not ...
Trap29's user avatar
  • 11
0 votes
1 answer
190 views

I have a windows application and i am using WineHQ on my mac to run this app. The application is a specific numerical solver for physics. Everytime a physics problem is to be solved, certain initial ...
eurekaman7's user avatar
0 votes
2 answers
57 views

I am attempting to use the [[ ]] operator in Bash and failing badly. My script is: #!/bin/bash # Test driver for the ProtectDatae script set -o xtrace # [[ -z "$1" ]] || source="$1&...
Jonathan's user avatar
  • 2,927