Thursday, February 16, 2017

If..then Exercises

My Linux Learning Path

Do Linux to learn Linux. Create a directory in Desktop for this purpose.

  1. Use Bash exit parameter to assert the following condition test:
    • 3 >= 6
    • 2 = 7
    • 56 <= 12
    • (10^3) = 1000
  2. Create a script that accept two parameters (only) and use if .. then to assert previous relations (one script for relation). Script output must be 0 and 1 (true or false).
  3. In the previous exercises when script file is created, permission does not allow execution. Before changing permission use if .. then control flow to assert if file is: readable, executable and writable.
  4. Write a script that request two numbers: num1, num2. Next identify if:
    • num1 = num2
    • num1 > num2
    • num1 < num2
  5. write a script that request a number: num1. Next identify if:
    • num is positive and greater than 10.
    • num is positive and greater than 20.
    • num is negative and greater than -10.
    • num is negative and greater than -20.
    • num belongs to range [-10,7].
    • num belongs to range [-10,7).
    • num belongs to range (-10,7].
    • num belongs to range (-10,7).
  6. Identify the meaning of the following file test operators. Write an example of each in the console. Next Write a script that accept one (only) input parameter and identify how to use each operator:
    • -e ________________________.
    • -f ________________________.
    • -d ________________________.
    • -s ________________________.
    • -w ________________________.
    • -r ________________________.
    • -p ________________________.
  7. Identify how to mix previous file operators. For example test if xxxx.sh is executable and empty.
  8. Match Integer comparison operator
    • -eq           !=
    • -ne           <
    • -gt           >=
    • -lt           <=
    • -ge           >
    • -le           =
  9. Provide 3 examples of Nested if .. then condition test.
  10. Create a nested if then condition test considering. For this purpose create a script that request a number and test:
    • Number is positive or negative.
    • Number belongs to range [1,10] or [-1,-10].
    • Number * 3 belongs to range [10,20] or [-15,-40].

No comments:

Post a Comment