Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
i have a bash shell scripting code Code: $ vi sayH # #Script to read your name from key-board # echo "Your first name please:" read fname echo "Hello $fname, ...
  1. #1
    Linux User bilal_jan's Avatar
    Join Date
    Mar 2008
    Location
    Pakistan
    Posts
    281

    linux bash scrupting error

    i have a bash shell scripting code
    Code:
    $ vi sayH
    #
    #Script to read your name from key-board
    #
    echo "Your first name please:"
    read fname
    echo "Hello $fname, Lets be friend!"
    when i run this from console i get the output with one error
    Code:
    ./test line 1: $: command not found
    Your first name please:
    Ahmed
    Hello Ahmed, 
    Lets be friend!
    secondly i wanna know that is there any advantage of learnig linux bash shell scripting or it is useless.

  2. #2
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    hi,


    at the very beginning of your script you should put
    Code:
    #!/bin/bash
    to tell the computer how to run your script.

    regarding shell script its very useful if you wanna keep using Linux(or Unix by the way) as it will help you automate things
    Linux and me it's a love story

  3. #3
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    Is the line:

    Code:
    $ vi sayH
    in the file? If so that is what's causing the error. Just comment out this line by putting a # at the beginning
    Linux User #453176

  4. #4
    Linux User bilal_jan's Avatar
    Join Date
    Mar 2008
    Location
    Pakistan
    Posts
    281
    thanks khafa for reply can u please tell me any site wh shows how can i automate my linux os.
    thanks

  5. #5
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    Quote Originally Posted by bilal_jan View Post
    thanks khafa for reply can u please tell me any site wh shows how can i automate my linux os.
    thanks
    automating things in Linux is a process that depends on who is doing it. so im afraid there is no rule of thumb. there is one book that is quite interesting (but you need to know about scripting before you can attempt to automate things), the title is "wicked cool shell scripts". it will give you very good ideas about how to automate things
    Linux and me it's a love story

  6. #6
    Linux User bilal_jan's Avatar
    Join Date
    Mar 2008
    Location
    Pakistan
    Posts
    281
    yes keren
    Code:
    $ vi sayH
    is in the file.
    i got this code from the following link
    Code:
    http://www.freeos.com/guides/lsst/ch02sec10.html

  7. #7
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    i followed the link to see and what the guy meant is to open the file sayH with vi which gives
    Code:
    vi sayH
    then you put the content(do not put the vi part in the file).

    and put what follows at the first line(it can help you avoid some headache)
    Code:
    #!/bin/bash
    Linux and me it's a love story

  8. #8
    Linux User bilal_jan's Avatar
    Join Date
    Mar 2008
    Location
    Pakistan
    Posts
    281
    oh k Khafa thats great
    tell me is there IDE for shell scripting or i have to use knosole to run shell scripting.

  9. #9
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    i dont think you need any IDE to write your shell scripts as they are plain text files.
    you just open a text file you put the instructions in there, then you save and make it executable(if you want) and run it. thats all

    run the following command and it should give you many files in your system and you can open them with more or less to see how they are written.
    Code:
    find / -type f -name "*.sh" 2> /dev/null
    Linux and me it's a love story

  10. #10
    Linux User bilal_jan's Avatar
    Join Date
    Mar 2008
    Location
    Pakistan
    Posts
    281
    so u wanna say that the code must look like this
    Code:
    #!/bin/bash
    #$ vi sayH
    #
    #Script to read your name from key-board
    #
    echo "Your first name please:"
    read fname
    echo "Hello $fname, Lets be friend!"
    but i have one question
    what was the reason to include the commented line
    #!/bin/bash

Page 1 of 2 1 2 LastLast

Posting Permissions

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