Skip to content

Download Labs-C02-bash-EN.pdf
Download SLIDE-Labs-C02-bash-EN.pdf

Environment variables

  • Display all of your environment variables.
  • Give the meaning of PATH, PS1, HOME, and TERM
  • Create a variable PS1_COPY to store the actual $PS1 value
  • Try to change PS1 in your current SHELL by "Hello type a SHELL command $"
  • Using the $PS1_COPY reinitialize your PS1 environment variable to the last value

TP_Protect_a_variable

  • Define a variable MyVar with a value of "ISEN"
  • Display the value of MyVar with the SHELL command echo
  • How could you display the string "ISEN is good for you" using the variable MyVar ?
  • Now display in one command echo, the name of the variable MyVar and her value. Example : "$MyVar = ISEN"
  • Use the following command : ls| wc -l and store the result in a variable named LS_COUNT.

TP_Scripting_Base

  • Explain the result of the following script:
#!/bin/bash
MyVar="I am a variable"
MyScript=$(basename $0)
echo -e "My script name is $MyScript\n and my var is $MyVar"
  • Write a script which sorts in alphabetical order all keyboard entries up to the JAIFINI string
  • Write a script which asks the user's last name, first name and preferred color and which answers (for each information, a specific question must be asked): Hello Mr. <NAME> <Firstname>. I agree with you. The color <COLOR> is a very nice color.

Scripting Base

Test

Write a script that indicates if the first argument is greater than the second.

Read

Write a script which asks the user for 2 numbers and tells the user if the first is greater than the second (obligation: read).

Algo

Calculator : case

Write a script that realizes a calculator. (obligation: case).

File Type : if/elif/else

Write a script to identify the type of file given in argument. (type = symbolic link/regular file/ directory/other; oblication : if/elif/else )

Backup : for/find

Write a script that creates a backup copy, suffixed by '-old', of all files in the folder given as argument. The backup should be recursive and only files. (obligation: for/find)

Game : while/read

Write a script that randomly chooses a number between 1 and 50. And asks the user to find it. With each proposal, indicate to the user if the number to find is higher/lower. (obligation : while/read)

TP_Process_Management

  • Start the command sleep 9999. How to regain access to the console without stopping the command?
  • How do I know if the previous command still works?
  • Start the command sleep 9999. How to regain access to the console and quitting the process?
  • What is the solution to launch the command sleep 9999 while immediately recovering control on the console but that the command continues to work.