Saturday, November 20, 2010

Linux Part 2 Lesson 1

Bash Scripts. Make Your own executable shells

Part 2 is about scripts. How do we write a script, what's the syntax and how do we make it executable?

First, there is a basic rule! In the first line we write:
#!/bin/bash
to determine that the script we write is a bash script. (Don't know what is a bash? See Part 1 lesson 1)

And after that we can write code.
Let's see what steps do we need to follow to make a bash script of Part 1 Lesson 4

Bash Scripts can take arguments, which we can access in the script
$index
i.e $1 is the first argument given in the command line.

The code is similar to those we wrote in the command line. However, now we have to make a text file which will contain our code.
We'll use a command line text editor, nano.
->type nano in the command line and press enter.

now determine which script to use (don't know what to write? Start from the beginning again)

This script will get your favourite artist from the command line, and add any songs found in the playlist.

The previous code was:
for music in *line*Dion*/*/*.wma; do
audacious -e "$music" &
done

know, it will be:

for music in $1/*/*.wma; do
audacious -e "$music" &
done

press control O and give a name to the file and then enter to save it. Remember, it will be saved in your current directory.

->Make it executable! How? With chmod +x nameOfScript
copy it in the /bin directory so it can be run any time
->now run it:
nameOfScript *Dion*


Notes:
  1. if you have permission problems with copying to /bin use sudo or login as root and copy it there.
  2. We named our script AddToAudaciousPlaylist
  3. It is a good name to remember what it does!
  4. Remember not to put .wma if your songs are mp3.
  5. And the question of the day: How will we make user to choose the song format? Think about it! Next lesson is about improving our script!!!

And yeahhh! You have make your own first open source program in linux!What is open source? ;)
Remember! The script should be run in the directory that your music files live! Like before!

2 comments:

  1. Bet of the day Casino – What time does the day come and go?
    Bet of the day and go! 토토 축구 중계 부띠끄 See everything air jordan 18 retro men to me we know about gambling air jordan 18 retro red suede sale in the UK. ✓Our expert team monitors every single how to get air jordan 18 retro racer blue day air jordan 18 retro yellow suede good website to ensure every one of the

    ReplyDelete
  2. And, after all, we take a look at each on line casino we list on our websitebefore writing a complete review. Please remember that that|do not neglect that} our guides and all gambling sites are only for people who 메리트카지노 are themselves} 18+. Also, check with local legal guidelines search out|to search out} out if online gambling is legal in your area. Wagering necessities are 35x, whereas eligible games are slots, keno, scratch playing cards, and board games. Then, you'll be able to|you possibly can} keep on making 4 more deposits, and Las Atlantis will match every one by 280%.

    ReplyDelete