Require command line argument for script to run [closed]
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I'm trying to require a script to only run if the command line argument provided is a specific text file called dailyUserProcs.20181203 in the same directory as the script. I am also running Putty.
Currently I am requiring any input to run the script, shown below.
if [ -z "$1" ] then
echo" No argument"
exit 1
fi
linux bash arguments
closed as off-topic by Jeff Schaller, Sparhawk, G-Man, RalfFriedl, JigglyNaga Dec 5 at 10:47
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, Sparhawk, RalfFriedl, JigglyNaga
add a comment |
up vote
0
down vote
favorite
I'm trying to require a script to only run if the command line argument provided is a specific text file called dailyUserProcs.20181203 in the same directory as the script. I am also running Putty.
Currently I am requiring any input to run the script, shown below.
if [ -z "$1" ] then
echo" No argument"
exit 1
fi
linux bash arguments
closed as off-topic by Jeff Schaller, Sparhawk, G-Man, RalfFriedl, JigglyNaga Dec 5 at 10:47
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, Sparhawk, RalfFriedl, JigglyNaga
2
Why require that specific argument if it's static?
– Jeff Schaller
Dec 4 at 23:21
Honestly I agree there is no reason for it, but sadly this is for a class assignment and is required.
– SoggyJ
Dec 4 at 23:31
So you've learned about test ([) and $1... what did you try for comparing $1 to a string?
– Jeff Schaller
Dec 5 at 0:14
Wow, thanks for the comment. Just figured it out after reading your comment. Appreciate it!
– SoggyJ
Dec 5 at 0:31
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to require a script to only run if the command line argument provided is a specific text file called dailyUserProcs.20181203 in the same directory as the script. I am also running Putty.
Currently I am requiring any input to run the script, shown below.
if [ -z "$1" ] then
echo" No argument"
exit 1
fi
linux bash arguments
I'm trying to require a script to only run if the command line argument provided is a specific text file called dailyUserProcs.20181203 in the same directory as the script. I am also running Putty.
Currently I am requiring any input to run the script, shown below.
if [ -z "$1" ] then
echo" No argument"
exit 1
fi
linux bash arguments
linux bash arguments
edited Dec 4 at 23:22
asked Dec 4 at 23:19
SoggyJ
62
62
closed as off-topic by Jeff Schaller, Sparhawk, G-Man, RalfFriedl, JigglyNaga Dec 5 at 10:47
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, Sparhawk, RalfFriedl, JigglyNaga
closed as off-topic by Jeff Schaller, Sparhawk, G-Man, RalfFriedl, JigglyNaga Dec 5 at 10:47
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, Sparhawk, RalfFriedl, JigglyNaga
2
Why require that specific argument if it's static?
– Jeff Schaller
Dec 4 at 23:21
Honestly I agree there is no reason for it, but sadly this is for a class assignment and is required.
– SoggyJ
Dec 4 at 23:31
So you've learned about test ([) and $1... what did you try for comparing $1 to a string?
– Jeff Schaller
Dec 5 at 0:14
Wow, thanks for the comment. Just figured it out after reading your comment. Appreciate it!
– SoggyJ
Dec 5 at 0:31
add a comment |
2
Why require that specific argument if it's static?
– Jeff Schaller
Dec 4 at 23:21
Honestly I agree there is no reason for it, but sadly this is for a class assignment and is required.
– SoggyJ
Dec 4 at 23:31
So you've learned about test ([) and $1... what did you try for comparing $1 to a string?
– Jeff Schaller
Dec 5 at 0:14
Wow, thanks for the comment. Just figured it out after reading your comment. Appreciate it!
– SoggyJ
Dec 5 at 0:31
2
2
Why require that specific argument if it's static?
– Jeff Schaller
Dec 4 at 23:21
Why require that specific argument if it's static?
– Jeff Schaller
Dec 4 at 23:21
Honestly I agree there is no reason for it, but sadly this is for a class assignment and is required.
– SoggyJ
Dec 4 at 23:31
Honestly I agree there is no reason for it, but sadly this is for a class assignment and is required.
– SoggyJ
Dec 4 at 23:31
So you've learned about test ([) and $1... what did you try for comparing $1 to a string?
– Jeff Schaller
Dec 5 at 0:14
So you've learned about test ([) and $1... what did you try for comparing $1 to a string?
– Jeff Schaller
Dec 5 at 0:14
Wow, thanks for the comment. Just figured it out after reading your comment. Appreciate it!
– SoggyJ
Dec 5 at 0:31
Wow, thanks for the comment. Just figured it out after reading your comment. Appreciate it!
– SoggyJ
Dec 5 at 0:31
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
To test if a file exists, use -f
.
To test if two strings are equal, use ==
(and similarly not equal is !=
).
To negate something, use !
.
To logical or two tests, use ||
.
Putting this all together, you get
if [ ! -f "$1" ] || [ "$1" != "dailyUserProcs.20181203" ]; then
echo Invalid Argument
exit 1
fi
echo Argument exists and is correct
# ... rest of code
This can all be found by typing info test
, and reading the documentation.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
To test if a file exists, use -f
.
To test if two strings are equal, use ==
(and similarly not equal is !=
).
To negate something, use !
.
To logical or two tests, use ||
.
Putting this all together, you get
if [ ! -f "$1" ] || [ "$1" != "dailyUserProcs.20181203" ]; then
echo Invalid Argument
exit 1
fi
echo Argument exists and is correct
# ... rest of code
This can all be found by typing info test
, and reading the documentation.
add a comment |
up vote
0
down vote
accepted
To test if a file exists, use -f
.
To test if two strings are equal, use ==
(and similarly not equal is !=
).
To negate something, use !
.
To logical or two tests, use ||
.
Putting this all together, you get
if [ ! -f "$1" ] || [ "$1" != "dailyUserProcs.20181203" ]; then
echo Invalid Argument
exit 1
fi
echo Argument exists and is correct
# ... rest of code
This can all be found by typing info test
, and reading the documentation.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
To test if a file exists, use -f
.
To test if two strings are equal, use ==
(and similarly not equal is !=
).
To negate something, use !
.
To logical or two tests, use ||
.
Putting this all together, you get
if [ ! -f "$1" ] || [ "$1" != "dailyUserProcs.20181203" ]; then
echo Invalid Argument
exit 1
fi
echo Argument exists and is correct
# ... rest of code
This can all be found by typing info test
, and reading the documentation.
To test if a file exists, use -f
.
To test if two strings are equal, use ==
(and similarly not equal is !=
).
To negate something, use !
.
To logical or two tests, use ||
.
Putting this all together, you get
if [ ! -f "$1" ] || [ "$1" != "dailyUserProcs.20181203" ]; then
echo Invalid Argument
exit 1
fi
echo Argument exists and is correct
# ... rest of code
This can all be found by typing info test
, and reading the documentation.
answered Dec 5 at 2:22
SmoothJazz
161
161
add a comment |
add a comment |
2
Why require that specific argument if it's static?
– Jeff Schaller
Dec 4 at 23:21
Honestly I agree there is no reason for it, but sadly this is for a class assignment and is required.
– SoggyJ
Dec 4 at 23:31
So you've learned about test ([) and $1... what did you try for comparing $1 to a string?
– Jeff Schaller
Dec 5 at 0:14
Wow, thanks for the comment. Just figured it out after reading your comment. Appreciate it!
– SoggyJ
Dec 5 at 0:31