LinuxQuestions.org
Register a domain and help support LQ
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 10-08-2003, 02:55 PM   #1
GridX
LQ Newbie
 
Registered: Sep 2003
Location: Canada
Distribution: Fedora & Gentoo-uClinux
Posts: 15

Rep: Reputation: 0
I am lost, cant use if statement properly


Here is the thing, c++ is easier to use the if statement,

anyway thats why Icant figure it out in linux scripts



code:
file $1*|grep script # question 11, generates a list of script files, with a command line parameter.


# The nex line is questions 12,13 accepts the dir as command line argument
file $1*|grep script|sed 's/[a-zA-Z/_:]*//1'

this script accepts a directory as acommand line parameter then shows the scripts in that dir.


I want to modify this script file so that if a single command line parametr is not found, the script generates an error message, displays the correctg syntax and exits with a valueof 1.


I tried if [$#<1]
then .... my commands
echo "echo error statements"

else ....my commands if there is a commandline

exit (1)

fi etc....

I tried so many variations of if but I cant generate any error message when I leave out the first command line parameter.

if this were c++ I would go if(argc==1)
{ commands
} very simple
not in scripts

help man

GridX
 
Old 10-08-2003, 05:47 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Jessie, Linux Mint 17
Posts: 7,750

Rep: Reputation: 271Reputation: 271Reputation: 271
"I tried if [$#<1]"

Try putting some spaces in the command as syntax separators:
if [ $# < 1 ]

___________________________________
Be prepared. Create a LifeBoat CD.
http://users.rcn.com/srstites/LifeBo...home.page.html

Steve Stites
 
Old 10-08-2003, 06:39 PM   #3
GridX
LQ Newbie
 
Registered: Sep 2003
Location: Canada
Distribution: Fedora & Gentoo-uClinux
Posts: 15

Original Poster
Rep: Reputation: 0
man, I actually figured it out,

if [ $# -lt 1 ] you need spaces and the -lt


thanks

GridX
 
  


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
Windows 98 was lost when Linux 9 was installed. The partition was properly created. lereisch Linux - Software 1 06-14-2005 11:25 AM
System won't boot properly knoppix doesn't initialize properly rodewan Linux - Software 0 01-23-2005 04:35 PM
For Statement bendeco13 Linux - General 6 10-31-2004 06:31 PM
value is lost from a return statement! what?? ludeKing Programming 3 05-30-2004 09:32 PM
Suse 9, RH9 wont install properly. Mandrake 9 wont boot properly? Help. l2ich84 Linux - Newbie 1 01-31-2004 12:02 PM


All times are GMT -5. The time now is 08:30 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration