LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-04-2005, 06:16 AM   #1
nix101
LQ Newbie
 
Registered: Sep 2005
Posts: 1

Rep: Reputation: 0
bash scripting questions


I have 2 things i need help with.

1. How can i check if the contents of a variable contains spaces (for part of validating)

2. how do i create a help information when a "-h" swtich is used with my script?
 
Old 09-04-2005, 09:22 AM   #2
flower.Hercules
Member
 
Registered: Aug 2005
Distribution: Gentoo
Posts: 228

Rep: Reputation: 31
1. You could use the `cut -d' ' -f2` command to check to see if field 2 of the newly cut variable exists (it cuts up the variable by spaces), if it does, the variable contains spaces.

2.
Code:
if [ "$1" = "-h" ]
then
        echo "Help Menu"
fi
you can also check into set -h Help, that would be my quick fix. I'm prefer perl over shell scripting, so those fixes aren't that beautiful, but I hope they help.

Check out TLDP for more information on shell scripting.
 
Old 09-04-2005, 09:26 AM   #3
hfawzy
Member
 
Registered: Aug 2002
Location: Egypt
Distribution: Debian Sarge, Slackware 10.0
Posts: 163

Rep: Reputation: 30
1.
Code:
if [[ $my_variable == *" "* ]]; then
      my_variable contains spaces
else
      my_variable is ok
fi
2.
You could use getopts (see here), or just check if the -h option is passed to your program.

Code:
case $1 in
        -h)
                echo "Help"
         ;;
esac
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting questions stryka Programming 3 11-24-2005 11:46 PM
Bash scripting pete1234 Programming 1 09-27-2005 01:48 AM
Bash scripting questions irfanhab Programming 2 06-07-2004 12:13 PM
bash scripting -=MaGo=- Programming 16 08-30-2003 07:07 PM
Bash scripting NSKL Linux - General 2 06-08-2002 12:10 PM


All times are GMT -5. The time now is 04:10 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration