SlideShare a Scribd company logo
Scripting 101
My First Sony ^H^H^H hellscript

#!/bin/bash
echo “Hello World!”




$ sh script.sh
 Hello World
Output redirection
There are 3 file descriptors:               Examples:
   stdin, stdout and stderr.
                                            1.    ls -l > ls-l.txt
Basically you can:                          2.   grep da * 2> grep-errors.txt
    redirect stdout to a file              3.   grep da * 1>&2
    redirect stderr to a file              4.   grep * 2>&1
    redirect stdout to a stderr            5.   rm -f $(find / -name core) &>
                                                 /dev/null
    redirect stderr to a stdout
    redirect stderr and stdout to a file
    redirect stderr and stdout to
     stdout
    redirect stderr and stdout to stderr

1 'represents' stdout and 2 stderr.
Pipes

Pipes can redirect output from one command to
  another

Example:

$ cat /etc/passwd | grep „whoami‟
Variables
STR=“Hello World!”
OF=“/var/my-backup-$(date +%Y%m%d).tgz”



#!/bin/bash
STR=“Hello World!”
echo $STR



#!/bin/bash
OF=“/var/my-backup-$(date +%Y%m%d).tgz”
tar -cZf $OF /home/me/
Local variables

#!/bin/bash
HELLO=Hello
function hello {
    local HELLO=World
    echo $HELLO
}
echo $HELLO
hello
echo $HELLO
Conditions
if [expression];                    Examples:
then
    code if 'expression' is true.   #!/bin/bash
                                    if [ "foo" = "foo" ]; then
fi                                       echo “expression
                                         evaluated as true”
                                    fi


                                    #!/bin/bash
if … then                           T1="foo"
else                                T2="bar"
                                    if [ "$T1" = "$T2" ]; then
elseif                                   echo “expression
                                         evaluated as true”
                                    else
                                           echo “expression
                                           evaluated as false”
                                    fi
Loops

3 kinds of loops   Examples:

                   #!/bin/bash
 for loop         for i in `seq 1 10`; do
                     echo $i
 while loop       Done
 until loop
                   #!/bin/bash
                   COUNTER=0
                   while [ $COUNTER -lt 10 ]; do
                     echo “The counter is “ $COUNTER
                     let COUNTER=COUNTER+1
                   done
Assignment:

Write a linux shell script to automagically
create 1000 user accounts. Make sure their
default password is “Hello123”

(hint: you cannot set the pasword with the –p
option….)
Useful files and commands

nano, joe, vi (editors)
/etc/passwd
useradd
passwd
rm -rf

More Related Content

What's hot

Rc - The Plan 9 Shell
Rc - The Plan 9 ShellRc - The Plan 9 Shell
Rc - The Plan 9 Shell
twopoint718
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basics
Manav Prasad
 
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Zyxware Technologies
 
Neoito — *NIX kungfu for web devs
Neoito — *NIX kungfu for web devsNeoito — *NIX kungfu for web devs
Neoito — *NIX kungfu for web devs
Neoito
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting BasicsSudharsan S
 
Unix And C
Unix And CUnix And C
Unix And CDr.Ravi
 
Scripting ppt
Scripting pptScripting ppt
Scripting ppt
anamichintu
 
Unix shell scripting
Unix shell scriptingUnix shell scripting
Unix shell scripting
Pavan Devarakonda
 
Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本
Lingfei Kong
 
TDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streamsTDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streams
tdc-globalcode
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell ScriptDr.Ravi
 
Popstat1 sh
Popstat1 shPopstat1 sh
Popstat1 sh
Ben Pope
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
Jaibeer Malik
 
Unix Basics
Unix BasicsUnix Basics
Unix BasicsDr.Ravi
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
Manav Prasad
 
De 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKDe 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWK
Adolfo Sanz De Diego
 
Shell programming 1.ppt
Shell programming  1.pptShell programming  1.ppt
Shell programming 1.ppt
Kalkey
 

What's hot (20)

Rc - The Plan 9 Shell
Rc - The Plan 9 ShellRc - The Plan 9 Shell
Rc - The Plan 9 Shell
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basics
 
Unix lab manual
Unix lab manualUnix lab manual
Unix lab manual
 
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
 
Neoito — *NIX kungfu for web devs
Neoito — *NIX kungfu for web devsNeoito — *NIX kungfu for web devs
Neoito — *NIX kungfu for web devs
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
 
Unix And C
Unix And CUnix And C
Unix And C
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Scripting ppt
Scripting pptScripting ppt
Scripting ppt
 
Unix shell scripting
Unix shell scriptingUnix shell scripting
Unix shell scripting
 
Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本
 
TDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streamsTDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streams
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell Script
 
Popstat1 sh
Popstat1 shPopstat1 sh
Popstat1 sh
 
Chap06
Chap06Chap06
Chap06
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
Unix Basics
Unix BasicsUnix Basics
Unix Basics
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
De 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKDe 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWK
 
Shell programming 1.ppt
Shell programming  1.pptShell programming  1.ppt
Shell programming 1.ppt
 

Viewers also liked

adele someone like you lyrics
adele someone like you lyricsadele someone like you lyrics
adele someone like you lyrics
mp3download
 
Mesa: "Las vacunas y los trasplantes ¿son servicios básicos de salud o un luj...
Mesa: "Las vacunas y los trasplantes ¿son servicios básicos de salud o un luj...Mesa: "Las vacunas y los trasplantes ¿son servicios básicos de salud o un luj...
Mesa: "Las vacunas y los trasplantes ¿son servicios básicos de salud o un luj...
PHARMACOSERÍAS
 
JOSE AVILA - Utilidad del Big Data en predicción de riesgos
JOSE AVILA - Utilidad del Big Data en predicción de riesgosJOSE AVILA - Utilidad del Big Data en predicción de riesgos
JOSE AVILA - Utilidad del Big Data en predicción de riesgos
COM SALUD
 
JULIO MAYOL - ¿Es necesario monitorizar todo?
JULIO MAYOL - ¿Es necesario monitorizar todo?JULIO MAYOL - ¿Es necesario monitorizar todo?
JULIO MAYOL - ¿Es necesario monitorizar todo?
COM SALUD
 
Atlantica XXII se presenta en Cangas de Onis (2009) con Xuán Cándano y Fernan...
Atlantica XXII se presenta en Cangas de Onis (2009) con Xuán Cándano y Fernan...Atlantica XXII se presenta en Cangas de Onis (2009) con Xuán Cándano y Fernan...
Atlantica XXII se presenta en Cangas de Onis (2009) con Xuán Cándano y Fernan...
PHARMACOSERÍAS
 
"La Salud un manantial de risas"
"La Salud un manantial de risas""La Salud un manantial de risas"
"La Salud un manantial de risas"
PHARMACOSERÍAS
 

Viewers also liked (6)

adele someone like you lyrics
adele someone like you lyricsadele someone like you lyrics
adele someone like you lyrics
 
Mesa: "Las vacunas y los trasplantes ¿son servicios básicos de salud o un luj...
Mesa: "Las vacunas y los trasplantes ¿son servicios básicos de salud o un luj...Mesa: "Las vacunas y los trasplantes ¿son servicios básicos de salud o un luj...
Mesa: "Las vacunas y los trasplantes ¿son servicios básicos de salud o un luj...
 
JOSE AVILA - Utilidad del Big Data en predicción de riesgos
JOSE AVILA - Utilidad del Big Data en predicción de riesgosJOSE AVILA - Utilidad del Big Data en predicción de riesgos
JOSE AVILA - Utilidad del Big Data en predicción de riesgos
 
JULIO MAYOL - ¿Es necesario monitorizar todo?
JULIO MAYOL - ¿Es necesario monitorizar todo?JULIO MAYOL - ¿Es necesario monitorizar todo?
JULIO MAYOL - ¿Es necesario monitorizar todo?
 
Atlantica XXII se presenta en Cangas de Onis (2009) con Xuán Cándano y Fernan...
Atlantica XXII se presenta en Cangas de Onis (2009) con Xuán Cándano y Fernan...Atlantica XXII se presenta en Cangas de Onis (2009) con Xuán Cándano y Fernan...
Atlantica XXII se presenta en Cangas de Onis (2009) con Xuán Cándano y Fernan...
 
"La Salud un manantial de risas"
"La Salud un manantial de risas""La Salud un manantial de risas"
"La Salud un manantial de risas"
 

Similar to Scripting 101

390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.ppt
mugeshmsd5
 
What is a shell script
What is a shell scriptWhat is a shell script
What is a shell script
Dr.M.Karthika parthasarathy
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
Kenneth Geisshirt
 
First steps in C-Shell
First steps in C-ShellFirst steps in C-Shell
First steps in C-Shell
Brahma Killampalli
 
Bash shell
Bash shellBash shell
Bash shellxylas121
 
34-shell-programming.ppt
34-shell-programming.ppt34-shell-programming.ppt
34-shell-programming.ppt
KiranMantri
 
2-introduction_to_shell_scripting
2-introduction_to_shell_scripting2-introduction_to_shell_scripting
2-introduction_to_shell_scriptingerbipulkumar
 
Unit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell scriptUnit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell scriptroot_fibo
 
Raspberry pi Part 25
Raspberry pi Part 25Raspberry pi Part 25
Raspberry pi Part 25
Techvilla
 
UNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming ConstructsUNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming Constructs
Nihar Ranjan Paital
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
vibrantuser
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
Raghu nath
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell ScriptingRaghu nath
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
Ashrith Mekala
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
Geeks Anonymes
 
Shell programming
Shell programmingShell programming
Shell programming
Moayad Moawiah
 
Scripting ppt
Scripting pptScripting ppt
Scripting ppt
anamichintu
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
vibrantuser
 

Similar to Scripting 101 (20)

390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.ppt
 
What is a shell script
What is a shell scriptWhat is a shell script
What is a shell script
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
First steps in C-Shell
First steps in C-ShellFirst steps in C-Shell
First steps in C-Shell
 
Bash shell
Bash shellBash shell
Bash shell
 
34-shell-programming.ppt
34-shell-programming.ppt34-shell-programming.ppt
34-shell-programming.ppt
 
2-introduction_to_shell_scripting
2-introduction_to_shell_scripting2-introduction_to_shell_scripting
2-introduction_to_shell_scripting
 
Unit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell scriptUnit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell script
 
Raspberry pi Part 25
Raspberry pi Part 25Raspberry pi Part 25
Raspberry pi Part 25
 
UNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming ConstructsUNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming Constructs
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Bash
BashBash
Bash
 
Shell programming
Shell programmingShell programming
Shell programming
 
Scripting ppt
Scripting pptScripting ppt
Scripting ppt
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
 

Recently uploaded

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 

Recently uploaded (20)

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 

Scripting 101

  • 2. My First Sony ^H^H^H hellscript #!/bin/bash echo “Hello World!” $ sh script.sh  Hello World
  • 3. Output redirection There are 3 file descriptors: Examples: stdin, stdout and stderr. 1. ls -l > ls-l.txt Basically you can: 2. grep da * 2> grep-errors.txt  redirect stdout to a file 3. grep da * 1>&2  redirect stderr to a file 4. grep * 2>&1  redirect stdout to a stderr 5. rm -f $(find / -name core) &> /dev/null  redirect stderr to a stdout  redirect stderr and stdout to a file  redirect stderr and stdout to stdout  redirect stderr and stdout to stderr 1 'represents' stdout and 2 stderr.
  • 4. Pipes Pipes can redirect output from one command to another Example: $ cat /etc/passwd | grep „whoami‟
  • 5. Variables STR=“Hello World!” OF=“/var/my-backup-$(date +%Y%m%d).tgz” #!/bin/bash STR=“Hello World!” echo $STR #!/bin/bash OF=“/var/my-backup-$(date +%Y%m%d).tgz” tar -cZf $OF /home/me/
  • 6. Local variables #!/bin/bash HELLO=Hello function hello { local HELLO=World echo $HELLO } echo $HELLO hello echo $HELLO
  • 7. Conditions if [expression]; Examples: then code if 'expression' is true. #!/bin/bash if [ "foo" = "foo" ]; then fi echo “expression evaluated as true” fi #!/bin/bash if … then T1="foo" else T2="bar" if [ "$T1" = "$T2" ]; then elseif echo “expression evaluated as true” else echo “expression evaluated as false” fi
  • 8. Loops 3 kinds of loops Examples: #!/bin/bash  for loop for i in `seq 1 10`; do echo $i  while loop Done  until loop #!/bin/bash COUNTER=0 while [ $COUNTER -lt 10 ]; do echo “The counter is “ $COUNTER let COUNTER=COUNTER+1 done
  • 9. Assignment: Write a linux shell script to automagically create 1000 user accounts. Make sure their default password is “Hello123” (hint: you cannot set the pasword with the –p option….)
  • 10. Useful files and commands nano, joe, vi (editors) /etc/passwd useradd passwd rm -rf