Advertisement
Gianvy

Esercitazione di Venerdì 23 Marzo 2018

Mar 23rd, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.54 KB | None | 0 0
  1. #============= for3.sh ==================
  2. #!/bin/sh
  3. #metodo veloce: echo $*
  4. for par
  5. do
  6.     echo $par
  7. done
  8.  
  9.  
  10.  
  11. #============= es29.sh ==================
  12. #!/bin/sh
  13. if test $# -ne 1
  14.     then echo Inserire un argomento; exit 1;
  15. fi
  16. if test ! -d $1
  17.     then echo Inserire una directory; exit 2;
  18. fi
  19.  
  20. cd $1
  21. count1=0
  22. count2=0
  23. for str in *
  24. do
  25.     if test -f $str
  26.     then
  27.         echo F $str
  28.         count1=`expr $count1 + 1`
  29.     fi
  30.    
  31.     if test -d $str
  32.     then
  33.         echo D $str
  34.         count2=`expr $count2 + 1`
  35.     fi
  36. done
  37.  
  38. echo File trovate: $count1
  39. echo Dir trovate: $count2
  40.  
  41.  
  42.  
  43. #=========== es28.sh ===================
  44. #!/bin/sh
  45. for file in *
  46. do
  47.     if test -f $file
  48.     then
  49.         grep '#!/bin/sh' $file > /dev/null
  50.         if test $? -eq 0
  51.         then
  52.             echo $file 
  53.         fi
  54.     fi
  55. done
  56.  
  57. #=========== es27.sh ====================
  58. #!/bin/sh
  59. for str in *
  60. do
  61.     if test -f $str
  62.     then
  63.         case $str in
  64.         *.sh) echo $str >&2;;
  65.         esac
  66.     fi
  67. done
  68.  
  69.  
  70. #=========== es26.sh ====================
  71. !/bin/sh
  72. if test $# -ne 1
  73. then
  74.     echo inserire un solo parametro;
  75.     exit 1;
  76. fi
  77. case $1 in
  78.     /*) echo nome assoluto;;
  79.     */*)echo nome relativo;;
  80.     *) echo nome relativo semplice;;
  81. esac
  82.  
  83.  
  84. #============ es25.sh ===================
  85. #!/bin/sh
  86. count=0
  87. ultimo=
  88. args=
  89. for par
  90. do
  91.     count=`expr $count + 1`
  92.     if test $count -eq $#
  93.     then
  94.         ultimo=$par
  95.     else
  96.         args="$args $par"
  97.     fi
  98. done
  99.  
  100. echo "Ultimo parametro: $ultimo"
  101. echo "Parametri: $args"
  102.  
  103.  
  104. #============ APPEND.SH ================
  105. #!/bin/sh
  106. case $# in
  107.     1)cat >> $1;;
  108.     2)cat < $1 >> $2;;
  109.     *)echo Inserire 1 o 2 parametri;;
  110. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement