

Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Prepara i tuoi esami
Studia grazie alle numerose risorse presenti su Docsity
Prepara i tuoi esami con i documenti condivisi da studenti come te su Docsity
Trova i documenti specifici per gli esami della tua università
Preparati con lezioni e prove svolte basate sui programmi universitari!
Rispondi a reali domande d’esame e scopri la tua preparazione
Riassumi i tuoi documenti, fagli domande, convertili in quiz e mappe concettuali
Studia con prove svolte, tesine e consigli utili
Togliti ogni dubbio leggendo le risposte alle domande fatte da altri studenti come te
Esplora i documenti più scaricati per gli argomenti di studio più popolari
Ottieni i punti per scaricare
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Una panoramica sui vari tipi di operatori disponibili in bash, tra cui operatori aritmetici, operatori di stringa e operatori di controllo. Viene inoltre illustrato come utilizzare le variabili, i file e le strutture di controllo. Il documento include anche esempi pratici per ogni tipo di operatore.
Tipologia: Formulari
1 / 2
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!


$ var=$(( 20 + 5 )) $ expr 1 + 3 # 4 $ expr 2 - 1 # 1 $ expr 10 / 3 # 3 $ expr 20 % 3 # 2 (remainder) $ expr 10 * 3 # 30 (multiply)
-d file ...is a directory -s file ...has a size greater than zero.
if [ condition ] # true = 0 then
elif [ condition1 ] then
elif condition then
else
fi
case expression in pattern1) execute commands ;; pattern2) execute commands ;; esac
while [ true ] do
done
until [ false ] do
done
for x in 1 2 3 4 5 # or for x in {1..5} do echo "The value of x is $x"; done
for ((x=1; x <= LIMIT ; x++)) do echo -n "$x " done
for file in *~ do echo "$file" done
break [n] # exit n levels of loop continue [n] # go to next iteration of loop n up
function-name arg1 arg2 arg3 argN
function function-name () {
return [integer] # optional }
$ local var=value
$ vars[2]=”two” # declare an array $ echo ${vars[2]} # access an element $ fruits=(apples oranges pears) # populate array $ echo ${fruits[0]} # apples - index from 0 $ declare -a fruits # creates an array
echo "Enter your favourite fruits: " read -a fruits echo You entered ${#fruits[@]} fruits for f in "${fruits[@]}" do echo "$f" done
$ array=( "${fruits[@]}" "grapes" ) # add to end $ copy="${fruits[@]}" # copy an array $ unset fruits[1] # delete one element $ unset fruits # delete array
for i in ${!fruits[@]} do echo fruits[$i]=${fruits[i]} done
$ var=”The quick brown fox” $ echo {var[0]} # The quick brown fox
$ echo ${arrayZ[@]//abc/xyz} # Replace all occurrences of abc with xyz
echo -n "Prompt: " read echo "You typed $REPLY."
echo -n "Prompt: " read response echo "You typed $response."
PS3="Choose a fruit: " select fruit in "apples" "oranges" "pears" do if [ -n "$fruit" ] then break fi echo "Invalid choice" done
$ dialog --menu "Choose" 10 20 4 1 apples 2 oranges 3 pears 4 bananas 2>/tmp/ans $ fruit=cat /tmp/ans $ echo $fruit
$ zenity --list --radiolist --column "Choose" --column "Fruit" 0 Apples 0 Oranges 0 Pears 0 Bananas > /tmp/ans $ fruit=cat /tmp/ans $ echo $fruit
exec 6<&0 # ‘Park’ stdin on # exec < temp.txt # stdin=file "temp.txt" read # from stdin until [ -z "$REPLY" ] do echo “$REPLY” # lists temp.txt read done exec 0<&6 6<&- # restore stdin echo -n "Press any key to continue" read
TMPFILE=mktemp on_break() { rm -f $TMPFILE exit 1 } trap on_break 2 # catches Ctrl+C
$ start=date +%s $ end=date +%s $ echo That took $((end-start)) seconds $ date +"%c" -d Fri 09 Apr 1954 12:00:00 AM GMT
$ in="The quick brown fox" $ out=echo $in | tr [:lower:] [:upper:] $ echo “$out” THE QUICK BROWN FOX
“ All the useful stuff on a single card”
#!/bin/bash $ chmod ugo+x shell_script.sh
$ bash [options] [file]
$ var=”some value” # declare a variable $ echo $var # access contents of variable $ echo ${var} # access contents of variable $ echo ${var:-”default value”} # with default $ var= # delete a variable $ unset var # delete a variable
$ var=ls *.txt # Variable contains output $ var=$(ls *.txt) # Alternative form $ cat myfile >/dev/null # suppress stdout $ rm nofile 2>/dev/null # suppress stderr $ cat nofile 2>/dev/null >/dev/null # suppress both