Find the answer to your Linux question:
Results 1 to 7 of 7
I write a shell script but now what i want to do is to use the test command and to be honest with you i really don't know, can someone ...
  1. #1
    Just Joined!
    Join Date
    Nov 2005
    Location
    UK
    Posts
    19

    shell and test command

    I write a shell script but now what i want to do is to use the test command and to be honest with you i really don't know, can someone give me some advices and how to use it?

    best regards dan,

  2. #2
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    if the man page is not clear, check this link out
    Linux and me it's a love story

  3. #3
    Just Joined!
    Join Date
    Nov 2005
    Location
    UK
    Posts
    19
    ok, i seen that page, but what i don't know is how to test it where to add that script?
    do i have to create another shell file or can be done inside the same file.


    regards dan,

  4. #4
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    what do you want to test?
    Linux and me it's a love story

  5. #5
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    While some more information would be useful, here is an example of test being used:
    Code:
    var1=5
    var2=6
    
    if [ "$var2" -gt "$var1" ]; then
        echo "var2 is greater than var1"
    fi
    Here I am using the (far more common) [ ... ] alias for test. "-gt" is the test for integer greater-than, so this tests if the value in $var2 is greater than the value in $var1.

    Does that help?
    DISTRO=Arch
    Registered Linux User #388732

  6. #6
    Just Joined!
    Join Date
    Nov 2005
    Location
    UK
    Posts
    19
    hello there, yeah a bit does help, the thing is, i have a shell file and i have to test it with test command, this is a coursework from school and everything is working well until this test command thing, i just need to test it, nothing much, so the code which you supply me above was great but where to add it, do i need to create a new shell file and then run it? or i should stick this code in the same shell fine? this is where i am lost......

    thanks for your help...

  7. #7
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    So as a general rule, homework questions are not allowed on the forum.

    I still don't understand your problem, so I can't even tell you where to find more information. This construct is a basic conditional statement: it allows you to have different behaviour depending on the status of the program or some input that the user gave.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...