- Can I suppress the error/warning /tmp/x.ksh[28]: getopts: y bad option(s)? I managed to do so doing while getopts kmg size_unit 2>/dev/null, is that the only way to do so?
Also, doesn't the following lines supposed to be executed if I run the script with the wrong command line option, i.e. /tmp/x.ksh -y, or if I run the script without any command line option, i.e. /tmp/x.ksh?
I have the if-then clause because the *) size="GB" line does not work like I expect it to. I've also tried ?) size="GB" or \?) size="GB" and it does not make any difference.
Code:
*) size="GB"
header="Filesystem GBytes Used Avail Capacity Mount"
echo "${header}" > ${tmp_header}
;;
esac
done
if [[ -z "${size}" ]] ; then
size="GB"
header="Filesystem GBytes Used Avail Capacity Mount"
echo "${header}" > ${tmp_header}
fi
Feedback will be much appreciated. Thanks in advance.
- Can I suppress the error/warning /tmp/x.ksh[28]: getopts: y bad option(s)? I managed to do so doing while getopts kmg size_unit 2>/dev/null, is that the only way to do so?
No, just put a colon in front of the option string: :kmg.
You need to check explicitly for no arguments.
I don't understand the last question, I get size=GB when I run your script with -y ...
Last edited by radoulov; 10-06-2011 at 11:37 AM..
Reason: Corrected: semicolon -> colon.
No, just put a colon in front of the option string: :kmg.
You need to check explicitly for no arguments.
I don't understand the last question, I get size=GB when I run your script with -y ...
Hi radoulov,
Thanks for your response.
I did what you suggested so now the getopts line looks like
Code:
while getopts :kmg size_unit
Now when I run /tmp/x.ksh -y, it runs the default that I want it to which is this one below here, i.e. size=GB is if I supplied an invalid option that is NOT k, m or g. However when I run /tmp/x.ksh without a command line option, it does not default to size=GB. Does that mean I have to do a separate check for when I do not specify a command line argument?
However when I run /tmp/x.ksh without a command line option, it does not default to size=GB. Does that mean I have to do a separate check for when I do not specify a command line argument?
Yes, as I already said you need to add code to handle that case.
Hint:
Also, why is size_unit showing ?, I thought it is supposed to parse to k,m or g but it is showing the ? character instead in all cases? WHY? -
Because:
Code:
When the end of options is encountered, getopts exits with a return value greater than zero. OPTIND is
set to the index of the first non-option argument, and name is set to ?.
Hi All,
I'm pretty new to this so please bear with me...
I'm trying to write a bash script to first search in a file for a string of characters; if the characters exist than skip the rest of the code until you get to the last line and run that command /sbdin/ldconfig; if the string doesn't... (2 Replies)
1.) I am to write scripts that will be phasetest folder in the home directory.
2.) The folder should have a set-up,phase and display files
I have written a small script which i used to check for the existing users and their password.
What I need help with:
I have a set of questions in a... (19 Replies)
Hello,
I am having a problem with Dual Booting Windows XP Pro and Linux Mint.
I have Three Hard Drives,
One Hard Drive has Linux Mint Loaded on it. When it is hooked up to the computer by itself it works great. This is an IDE Drive.
The Second Hard Drive has Window XP Pro loaded on it.... (3 Replies)
I am confused c#t#d#s# once I learn the following :
slice 0 ...... 0 to 2520
slice 1....... 2521 to 2840
slice 6........2841 to 8891
slice 2........0 to 8891
really really confused. Please explain. (8 Replies)
Hi,
One of the directory in my folder has the following persion :
drwxr-sr-x
Can any one explain this permission and how can his occur ? This folder is created with Win SCP. Any folder created with win SCP is being set to this permission only. (1 Reply)
A red hat linux ftp server exists in which a file exists. My problem is I need to connect to this server from my windows xp terminal which is in the same network & retrieve the file then convert it to xcel for some data
Pls advs commands and procedure to connect to the machine...oh my god... (1 Reply)
hi! how when i'm chattin inside com there was this chatter andi don't know what he did but he saw all my files inside my shell. what did he do? (4 Replies)
Hi,,,
is there any possibility to install Linux in my P.C which is use Win98 without loose anything from my hard disk????
----------------------------------------------------------------------------------
Is it better for a newbie in this kind of OS to install Linux instead of... (5 Replies)