Find the answer to your Linux question:
Results 1 to 8 of 8
i wrote this script, and everytime i run the script the code deletes and i want to know why EDIT: i also chmod 755 if anyone wanted to know Code: ...
  1. #1
    Just Joined!
    Join Date
    Apr 2007
    Posts
    6

    learning shell scripting

    i wrote this script, and everytime i run the script the code deletes and i want to know why

    EDIT: i also chmod 755 if anyone wanted to know

    Code:
    $ cat > ispostive
    #!bin/sh
    #
    # Script to see whether argument is postive
    #
    if test $1 -gt 0
    then
    echo "$1 number is postive"
    fi
    just so everyone knows i just started to learn shell scripting

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    the code deletes? u mean it did not get saved as file "ispositive"? how did you end you session affter you typed in those lines? using cat, to end the script you should type ctrl-d. a suggestion is to use an editor like vi or emacs etc to create your script.

  3. #3
    Just Joined!
    Join Date
    Apr 2007
    Posts
    6
    Quote Originally Posted by ghostdog74
    the code deletes? u mean it did not get saved as file "ispositive"? how did you end you session affter you typed in those lines? using cat, to end the script you should type ctrl-d. a suggestion is to use an editor like vi or emacs etc to create your script.
    umm i dont know those editer's i was useing gedit.. i guess i should learn how to use vi i guess?

  4. #4
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Quote Originally Posted by milonix
    umm i dont know those editer's i was useing gedit.. i guess i should learn how to use vi i guess?
    no its fine. use gedit, type in your script , save it as "ispositive" (or other names) , chmod it if necessary and you can then run the script with an argument. it should be fine.

  5. #5
    oz
    oz is online now
    forum.guy
    Join Date
    May 2004
    Location
    arch linux
    Posts
    18,097
    Quote Originally Posted by milonix
    i guess i should learn how to use vi i guess?
    If you should decide that you do want to learn vim, just run the vimtutor command for a quick lesson.
    oz

    new members/users: read this first | new member faq
    no private messages requesting computer support - post them on the forums!
    please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.

  6. #6
    Just Joined!
    Join Date
    Apr 2007
    Posts
    6
    i was following Linux Shell Scripting Tutorial (LSST) v1.05r3 and he use's $ cat > filename.. at the top of code so i thought i had to put that but it look's like thats just a command to start the file am i wrong?

  7. #7
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Quote Originally Posted by milonix
    i was following Linux Shell Scripting Tutorial (LSST) v1.05r3 and he use's $ cat > filename.. at the top of code so i thought i had to put that but it look's like thats just a command to start the file am i wrong?
    when you do : cat > filename on the shell, cat takes in standard input from the command line, ie whatever you type. to stop typing, you give ctrl-d to cat and it will save what you type to filename. this is essentially the same as what you do with gedit (or other editors).
    However, if you just do a cat:
    Code:
    # cat
    this is first line
    this is first line
    cat will echo what you type on the screen (stdout).
    please look at the cat man page for more details.

  8. #8
    Just Joined!
    Join Date
    Apr 2007
    Posts
    6
    Thanks for everyone's help

Posting Permissions

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