Raspberry pi Projects

  • introduction to Bash script

    the bash script which is the Linux shell programming language, it is necessary for all the beginners to learn this language to make
    easy understanding how Linux system work and how we use bash to do some tasks in the raspberry pi,
    in this lesson I will show you the most importing Linux shell command and how to make a execute program so let's begin.

    Shell command


    First open the Linux shell command by clicking on the icon "LXterminal" like the photo below.
    Post

    now you can type the command "who am I" and the answer it will be the username which is mostly "pi".

    command list

    • "pwd" this command showing the tree folder.
    • "cd" to jump from folder to another.
    • "cd.." to back from the folder you are in.
    • "ls" to list all the folders and file inside the folder.
    • "ls -l" to list all the folders and file directory.
    • "ls -a" to list all the folders and file even the hidden files inside the folder.
    • "ls -p" to list only the folders without the files.
    • "ls -lap" to list all the folders and files with all previous option.
    • "mkdir" to make a folder Example: mkdir A
    • "rmdir" to remove a folder Example: rmdir A
    • "cp" copy folder to another folder Example: cp A B
    • "cp -R" to copy all the folders and files to another folder Example: cp -R A B
    • "mv" moving the folder to another folder Example: mv A B
    • "man" to list information about specific command line Example: man ls
    • "where is" to search for specific folder or file Example: where is pi
    • "env" this command will show all the features of your device
    • "echo" print between the arrows Example: echo 'electro-think'
    • "cat" print on the screen what contains in the file Example: cat electro.txt
    • "history -c" to erase all the command line it's has been saved in the memory
    • "clean" to clean the screen command

    so these are the most necessary commands the beginners need it after that let's learn how to make the first bash script program with a few steps.
    First we type in the shell "sudo nano first_program.sh","sudo" it's an command which it's mean super user do,"nano" it's an editor environment for Linux
    "first_program.sh" the program name after that ".sh" to tall Linux this is a shell script program,after hitting enter we have a black screen now we can write the script we want it.
    #!/bin/bash
    echo 'hello world' #the echo command it's for printing the message 
    sleep 3 #delay for three seconds
    

    then save the file and write in shell command the following:

    "sudo chmod +x first_program.sh"

    "chmod +x" it's a permission command line to execute this file, without this command the program never work because the Linux system executes only the file which has been permission from the superuser.
    after that every time you type "./first_program.sh" the program will execute and print on the screen hello world and then it's make a delay for 3 seconds.