- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Checking the null entry in Shell Scripting
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-17-2007 11:57 PM
тАО06-17-2007 11:57 PM
I am trying to write a script for different options the user enters.
the small snippet is as follows
read Choice
if [ $Choice -eq 1 ]
then
...............
else
................
fi
Now the problem is i also want to check for the null i.e, if the user enters nothing in the console and presses enter.
How can i check this null in the script .
thanks in advance
Vikram
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-18-2007 12:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-18-2007 12:09 AM
тАО06-18-2007 12:09 AM
Re: Checking the null entry in Shell Scripting
read REPLY
case ${REPLY} in
0 ) echo "..."
;;
1 ) echo "..."
;;
"" ) echo "please enter something!"
;;
* ) echo "error!"
;;
esac
Regards!
...JRF...
- Tags:
- case
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-18-2007 12:14 AM
тАО06-18-2007 12:14 AM
Re: Checking the null entry in Shell Scripting
But i think you are talking about command line arguments.
the problem i am facing is with scanning the values using "read"
i have written like this
read Choice
if [ $Choice -eq 1 ] || [ -z $Choice ]
...........
fi
if i try to run the script and give enter in the console i.e null string it says
"Specify a parameter with this command"
But i think i have checked for the null also .
I am not understanding what should i do to satisfy the above if condition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-18-2007 12:15 AM
тАО06-18-2007 12:15 AM
Re: Checking the null entry in Shell Scripting
read input
if [ -z "$input" ]; then
# zero/empty input
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-18-2007 12:27 AM
тАО06-18-2007 12:27 AM
Re: Checking the null entry in Shell Scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-18-2007 12:59 AM
тАО06-18-2007 12:59 AM
Re: Checking the null entry in Shell Scripting
The user might type something strange, like ";cat /etc/passwd;".
This allows the user to by-pass the menu system and run commands directly. If the script is run as root (using a "setuid root" wrapper program or sudo), this gives the user a way to run any commands with unlimited access.
Even if this script is not security-critical, it's good to make a habit of always using quotes. It makes your scripts more robust and this way you're less likely to make dangerous mistakes elsewhere.
MK
- Tags:
- quoting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-18-2007 01:05 AM
тАО06-18-2007 01:05 AM
Re: Checking the null entry in Shell Scripting
$ if [ "$Choice" = "" ]; then