Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, I am stuck at some point with shell scripting. I want to write a shell script which can read commands in a text file and execute the commands. Suppose ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2012
    Posts
    4

    Post Shell Script Help


    Hi,

    I am stuck at some point with shell scripting.

    I want to write a shell script which can read commands in a text file and execute the commands.

    Suppose I have
    cp -r [etc]
    mkdir -p [etc]

    these commands are in a text file.

    I have written a script which can read from the file and display the lines but I want to execute the cp -r [etc] and mkdir -p [etc] with this script.

    So can anyone of you help me with this.

    Thank you.

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Hello and welcome,

    I am not sure I understand what you are asking.

    If you mean you want to execute the commands that are in a text file, make that text file executable and then run it, e.g.:

    Code:
    chmod +x script.sh
    Code:
    ./script.sh
    you can also simply source a script in Bash, e.g.:
    Code:
    . script.sh
    these commands will be run in your current shell, though, not a separate shell, as in the previous case.

    You can also post the content of your text/scripts, so that we may fully understand what you are after.

  3. #3
    Just Joined!
    Join Date
    Oct 2012
    Posts
    4
    No.. That's not what I was looking for.

    Anyways one of my friend helped me and thank you very much for your reply.

    He suggested I use eval $variable in the script so that the commands I get from the text file can be executed.

  4. $spacer_open
    $spacer_close
  5. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Great, glad you got it sorted.

    You can mark the thread as Solved if you're happy (see the Thread Tools at the top of the page).

Posting Permissions

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