Introduzione al Bash Scripting
Alex Scriven
Data Scientist
Nel Bash scripting, ci sono tre "stream" per il programma:
Per impostazione predefinita, questi stream leggono e scrivono dal terminale.
Puoi vedere 2> /dev/null nelle chiamate: reindirizza STDERR per eliminarlo. (1> /dev/null è STDOUT)
Rappresentazione grafica degli stream standard, usando la pipeline creata prima:

Considera un file di testo (sports.txt) con 3 righe.
football
basketball
swimming
Il comando cat sports.txt 1> new_sports.txt legge dal file e scrive lo STDOUT in un nuovo file. Prova cat new_sports.txt
football
basketball
swimming
Un concetto chiave in Bash è quello degli argomenti
Gli script Bash possono accettare argomenti aggiungendo uno spazio dopo il comando.
$: il primo è $1, il secondo $2, ecc.$@ e $* restituiscono tutti gli argomenti in ARGV$# restituisce il numero di argomentiConsidera uno script di esempio (args.sh):
#!/usr/bash
echo $1
echo $2
echo $@
echo "There are " $# "arguments"
Ora esegui bash args.sh one two three four five
one
two
one two three four five
Ci sono 5 argomenti
#!/usr/bash
echo $1
echo $2
echo $@
echo "There are " $# "arguments"
Introduzione al Bash Scripting