0

I have a file name myFirstFile that contains certain commands. But I am not able to excecute them.

If I want to execute this as a program, which code should be implemented?

1
  • 2
    You really need to read up on shell scripts. Commented Sep 8, 2012 at 9:31

3 Answers 3

2

If you want to execute your program, it should start with:

#!/bin/sh

It's the generic script file "header". It indicates that the script is a shell script (if it's bash script you should have #!/bin/bash, etc.). If you want to execute it, you should call chmod +x ./myFirstFile to give privileges to call it as program, and then you can start your script normally: ./myFirstFile.

Sign up to request clarification or add additional context in comments.

Comments

1

Make this file executable* and give it *.sh extention like: "myFirstFile.sh"

Than run it from terminal (or crontab - it can do things for you when you sleep :) ) like:

cd directory/you/have/that/file
sh ./myFirstFile.sh

*Im not shure that making it executable is the most secure thing you can do. All my sh scripts are and I never digged into this issue, so make sure its cool

Also make sure you have "#!/bin/bash" in first line - sometimes it helps (dont know why, Google it)

edit: for example my script for starting Minecraf server looks like this

start.sh

#!/bin/bash

BINDIR=$(dirname "$(readlink -fn "$0")")
cd "$BINDIR"

while true
do
    java -Xmx3584M -jar craftbukkit.jar

    echo -e 'If you want to completely stop the server process now, press ctrl-$
    echo "Rebooting in:"
    for i in {5..1}
    do
        echo "$i..."
        sleep 1
    done
    echo 'Restarting now!'
done

Comments

0

You have to make the file executable:

chmod +x myFirstFile

Then you can execute the commands in it:

./myFirstFile

1 Comment

thnks.... i am beginner in this language.. actually i have creted it n run the commands successfully...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.