How can i modify this script to echo an error msg and exit the script incase the user does not specify the -f option in the argument.
Out of a myriad of other possibilities: introduce a flag, set it to false initially, set it to true in the handling part of the "-f"-option and test for its status afterwards:
Why is it giving error when it should have worked ?
Can you please tell me whats wrong ??
Yes: you have put everything - including the shebang line, which makes absoultely no sense - into a function and then called the function with no arguments. What is getopts supposed to work on when there are no options provided, hm?
You could have found that out easily yourself by putting an echo-statement here:
and you would have immediately noticed that this part was not even executed. You could also have put a testwise echo-statement into the while-loop and show the values of "$opt" and "$OPTARG" during executing which would have yielded the same information. Finally you could have tried the sample script UNMODIFIEDLY first before you tinkered with it.
Don't get me wrong, it is meant to be tinkered with. But trying to understand it first before doing experiments (like putting everything into a function) is usually a good idea.
i am reading line by line from a file as below
while IFS= read -r var
do
...
...
...
done < "hello.txt"
I added the keytool command in the do while loop as below.
while IFS= read -r var
do
...
keytool -genkey -alias $fname -keyalg RSA -keystore $fname.jks -keysize 2048
...
done... (3 Replies)
I'm using getopts to process command line args in a Bash script. The code looks like this:
while getopts ":cfmvhs:t:" option; do
case $option in
c) operationMode="CHECK"
;;
f) operationMode="FAST"
;;
m) ... (6 Replies)
How can I say one of the options is required? can I use an if statement?
let say:
while getopts ":c:u:fp" opt; do
case $opt in
c) echo "-c was triggered, Parameter: $OPTARG" >&2;;
u) echo "-u was triggered, Parameter: $OPTARG" >&2;;
f) echo "-u was triggered,... (2 Replies)
i have the following scenario want to run the following script with manadory and optional argumnets
Manadory options are :
filename=""
port=""
optional arguments
type -t
balances -b bal
prices -p
./test filename port -t A -b bal
my code i have that won't parse the options is... (1 Reply)
Hello All,
I have shell script as below in a.ksh.
#! /usr/bin/ksh
while getopts a: b: ab:f: VAR
do
case $VAR in
a) A=${OPTARG}
echo $A;;
b) B=${OPTARG}
echo $B;;
ab) AB=${OPTARG}
echo $AB ;;
f) F=${OPTARG}
echo $F ;;
esac
done
When I execute sh a.ksh -a 1 -b 2 -ab 3 -f 4 as below... (7 Replies)
Hi, I'm having problems with a script where I wanted every single option specified in the command line to have an argument taken with it, but for some reason only d works in the code I will be showing below.
For example if I did ./thisfile -a something
it would come up with "a chosen with " as... (2 Replies)
Hi All,
How to enforce all users to change their password when they try to login.
I am having Solaris 9 and 10.
Even it would be much better if anyone can say to enforce all users to change their password next morning they login.
Thanks in advance,
Deepak (3 Replies)
Hi,
I need to implement something that will enforce login to a Solaris server as a particular, specifed user. After this login stage, users will be able to "su -" to whichever user they wish, by which time their activity will be captured by some sort of script (yet to be written). What I need... (7 Replies)
I need to create a shell script having the menu with few options such as
1. Listing 2. Change permissions 3. Modify Contents 4. Delete Files 5. Exit
1. For 1. Listing: Display a special listing of files showing their date of modification and access time (side by side) along with their... (2 Replies)
As a system administrator. sometimes we see the users are trying some commands dangerous for the system health and remove them from their individual coomand history file.
How it is possible to enforce that the normal usres will will not be able to modify the history.
Thanks in advance.
Partha (4 Replies)