Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Linux dalla Console - terza serata
Search
BgLUG
April 05, 2017
Programming
360
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Linux dalla Console - terza serata
Bash scripting
BgLUG
April 05, 2017
More Decks by BgLUG
See All by BgLUG
Introduzione a Python – Ecosistema Python e usi specifici
bglug
1
310
Introduzione a Python – Funzionalità di base e strutture dati
bglug
1
310
Linux dalla Console - quarta serata
bglug
0
230
Linux dalla Console - seconda serata
bglug
1
300
Linux dalla Console - prima serata
bglug
1
370
Other Decks in Programming
See All in Programming
新人はどこまで自力でやり、どこからAIに頼るべきか/エンジニア育成に向き合う_先輩たちの悩みと知見共有会
toppan_digital_dev
1
610
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
370
Omarchy Tokyo やると聞いて UMPC 買ってセットアップしてきた
mtsmfm
0
140
Webの地図
yosuke_furukawa
PRO
6
4.4k
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
2.6k
A2UI for Android: Safely Rendering AI-Generated UI with Jetpack Compose - DroidKaigi 2026
itsmedreamwalker
0
110
20260828_品質と開発生産性を両立させる、AI時代のE2Eテストの考え方
magicpod
0
200
新卒PdEのリアル
ryu1013
1
490
一参加者から『中の人』へ 〜全通PHPerがブースに立って学んだ、カンファレンスを100倍楽しむコツ〜
wp_daisuke
0
150
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
0
700
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
4.2k
【DroidKaigi 2026】「アクセシビリティを利用するとき、 アクセシビリティもまたこちらを利用している」 〜マルウェアによる攻撃と防衛について〜
halunoyo
0
460
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Making Projects Easy
brettharned
120
6.7k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
330
Heart Work Chapter 1 - Part 1
lfama
PRO
9
36k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.3k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
390
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
410
The World Runs on Bad Software
bkeepers
PRO
72
12k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
330
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
480
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Transcript
Linux dalla console — 3 Bash scripting Emiliano Vavassori 5
aprile 2017 FabLab Bergamo Patronato San Vincenzo, Bergamo Bergamo Linux Users Group 1
Sommario Generalità sullo scripting Programmazione in bash Variabili Controllo di
flusso Cicli Subshell Input dall’utente Argomenti Lavorare con i file 2
Generalità sullo scripting
Generalità Uno script è un file di testo contenente istruzioni
che un interprete (ad esempio la shell) esegue nell’ordine in cui le stesse istruzioni sono state inserite. bash può interpretare comandi interni o esterni: comandi propri della shell (if, for, test, …) o comandi esterni (ls, mkdir, grep, awk, …). 3
Cenni sull’esecuzione batch $ bash -c '<comando 1>; <comando 2>;
\ <comando 3>' 4
Qualche trucco per eseguire più comandi… $ <comando 1> &&
<comando 2> || <comando 3> $ <comando molto lungo> & $ fg $ nohup <comando> >logfile 5
Anatomia di uno script Estratto: nomescript.sh #!/bin/bash # Commenti <comando
1> <comando 2> <comando 3> <comando 4> # Ulteriori comandi 6
Eseguire uno script $ bash nomescript.sh 7
Eseguire uno script — Eseguibile? $ chmod +x nomescript.sh $
./nomescript.sh 8
Qualche altro trucco sugli eseguibili… Attenzione a chi do accesso
in esecuzione! $ chmod +x nomefile.sh || chmod u+x nomefile.sh Percorso di sistema — $PATH $ cp nomescript.sh $HOME/bin/; cd /tmp $ nomescript.sh 9
Programmazione in bash
Definizione delle variabili $ miavariabile="ciccio pasticcio" Variabili d’ambiente: $ export
MIAVAR="valore" 10
Distruzione di una variabile $ unset MIAVAR 11
Uso delle variabili $ echo "$miavariabile" > ciccio.txt $ echo
"${miavariabile}" > ciccio.txt 12
Controllo di flusso — if $ if [[ … ]];
then … elif [[ … ]]; then … else … fi 13
Controllo di flusso — case $ case $var in 1)
<comando 1> ;; 2-5) <comando 2> ;; *) <comando default> ;; esac 14
Ciclo for $ for f in <seq>; do … done
15
Sostituire i cicli con find e xargs $ find .
-iname \*.txt -exec chmod go-wx {} \; $ find /tmp -iname \*.sh | xargs grep sudo 16
Farsi ritornare il risultato di un comando $ var=` <comando
1> ` $ var=$( <comando 2> ) 17
Input dall’utente Caserecci: $ echo -n "Dimmi il tuo nome:
"; read var Un po’ più carini: $ var=`whiptail --inputbox "Dimmi il tuo nome:" \ 0 0 3>&1 1>&2 2>&3` 18
Non sempre comodo… Spesso e volentieri si preferisce chiedere input
all’utente tramite gli argomenti dello script. $ bash mioscript.sh argomento1 argomento2 19
Argomenti $0 Percorso e nome dello script $1 Primo argomento
$2 Secondo argomento … $@ Tutti gli argomenti $# Il numero degli argomenti passati 20
Lavorare con i file $ dirname $var $ basename $var
.ext 21