Linked Questions
15 questions linked to/from How to write a bash script that takes optional input arguments?
0
votes
1
answer
4k
views
Shell script to accept optional parameters [duplicate]
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 ...
3
votes
1
answer
2k
views
cd ${1:-.} what does that mean [duplicate]
#====================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, ...
-3
votes
1
answer
387
views
Default variable in bash when using -u flag? [duplicate]
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 ...
0
votes
1
answer
206
views
One liner if-else not working as intended [duplicate]
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 ...
0
votes
2
answers
90
views
Shell script to replace long predefined arguments [duplicate]
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 ...
2
votes
1
answer
66
views
Function with optional positional argument [duplicate]
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"
...
1463
votes
14
answers
972k
views
Assigning default values to shell variables with a single command in bash
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
...
64
votes
3
answers
40k
views
Using getopts inside a Bash function
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() {
...
15
votes
2
answers
25k
views
bash getopts multiple arguments or default value
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 ...
9
votes
3
answers
16k
views
Bash - function with optional arguments and missing logic
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 ...
1
vote
1
answer
3k
views
Angular: npm script with params
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-...
-1
votes
1
answer
576
views
.\create.sh: line 52: X: command not found
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 ...
0
votes
1
answer
419
views
how to add output of user input
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 ...
0
votes
1
answer
190
views
Making an elegant bash script
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 ...
0
votes
2
answers
57
views
Run commands on same line as [[ ]] operator
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&...