LinuxQuestions.org
Visit Jeremy's Blog.
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


Closed Thread
  Search this Thread
Old 07-02-2006, 05:35 AM   #1
bondoq
Member
 
Registered: Nov 2004
Posts: 77

Rep: Reputation: 13
shell script problem


i can't understand the if condition
this is an example but i can't understand what is th $1

$ cat > ispostive
#!/bin/sh
#
# Script to see whether argument is positive
#
if test $1 -gt 0
then
echo "$1 number is positive"
fi

plesae help me

thank you
 
Old 07-02-2006, 05:46 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,354
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
OK, he wasn't particularly clear on this, but what he meant is for you to report your thread. Then the forum moderator will move it to where he/she thinks it would be best or to your forum of choice. Though you probably did not have the intention, what you're doing now is crossposting and that's a waste of whatever it is that's valuable.
 
Old 07-02-2006, 06:19 AM   #3
SlackDaemon
Member
 
Registered: Mar 2006
Distribution: RedHat, Slackware, Experimenting with FreeBSD
Posts: 222

Rep: Reputation: 30
Ayup.. sorry. Should have explained that better.

Ok, in reference to your question regarding the difference between 'test' and [ expr ], there is not difference in functionality. It is purely a matter of preference. Lots of people prefer the [ expr ] form because it is similar to the syntax of other programming languages.
 
Old 07-02-2006, 06:29 AM   #4
bondoq
Member
 
Registered: Nov 2004
Posts: 77

Original Poster
Rep: Reputation: 13
i want to understand what is wrong is this script

if [ $1 -d ]

then

echo " this is a file not a directory "

fi
 
Old 07-02-2006, 07:38 AM   #5
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
Quote:
i want to understand what is wrong is this script
Try this...
Code:
#!/bin/bash
# Example: ./myscript file.txt

if ! [ -d $1 ] ; then
   echo " $1 is a file not a directory "
fi
fi
 
Old 07-02-2006, 09:58 AM   #6
Theorist
Member
 
Registered: Jun 2006
Distribution: FC5, FC3, RHEL 3, Debian 3.1, Debian 3.0
Posts: 56

Rep: Reputation: 15
Command Line Arguments

Hi bondoq,
Quote:
this is an example but i can't understand what is th $1
$1 is the first command line argument that you tried to pass to the script. For example : -
Quote:
$ ./script_name argument1 argument2 argument3 . . .
In this script you can access those command line arguments entered along with the script by $1 = argument1, $2 = argument2 and so on.

I suggest you to read this : -
http://www.phptr.com/articles/articl...&seqNum=4&rl=1

With Regards,
Theorist
 
Old 07-03-2006, 02:45 AM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

http://www.linuxquestions.org/rules.php
http://www.linuxquestions.org/questi...d.php?t=460215
 
  


Closed Thread


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
problem with C shell script stoneman Programming 2 12-22-2005 08:39 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
Shell script problem maringat Linux - Software 5 07-25-2005 05:12 PM
Shell-Script Problem? x4v013 Slackware 7 09-17-2003 12:15 AM
shell script problem steltner Linux - General 19 05-18-2003 02:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:15 AM.

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