MarioDS
MarioDS

Reputation: 13063

How to create and save a bash script

The teacher never explained us anything about unix and bash. He told us something about the history. Then he said how to fill in an IP address in a program called putty, which is the shell we used to work on the server. He basically gave us 7 series of exercises. We also had a book that was pretty useless. I mostly used internet and SO to help myself out, along with the commands I knew from DOS and the man/info pages.

The question is, what is the preferred text editor to make scripts? Internet says any will do but I know only cat. And then, how do I even begin? What I need is a crash course or something. I'm sorry I know this isn't the best kind of question to ask here but it's all I can think of atm. Don't blame me, but please do bash the teacher (pun intended).

Upvotes: 3

Views: 62917

Answers (2)

Sean Mee
Sean Mee

Reputation: 1

You could use the vi text editor, but it can be a bit tricky if you're starting out. I would try gedit if your using a GNOME environment

Upvotes: 0

Kyle
Kyle

Reputation: 14666

Try using vi as your text editor. Change to the directory you want your script to be saved in and then type in `vi myScript.sh". This will start the vi text editor. You can type in all your shell commands here.

Here's a link to a vi cheat sheet - http://linuxfordummies.org/tag/vi/

Once your in vi, you can type in one command on each line, you can use enter to move to the next line. After you have your script typed in, press : on the keyboard to open a prompt for vi. Once you have the : (colon) prompt at the bottom of the screen, enter wq for write/quit. This will save myScript.sh to the directory you started in. You should then be able to execute the script just by calling myScript.sh

I hope this helps, best of luck!

Upvotes: 5

Related Questions