Delete Set public Set private Add tags Delete tags
  Add tag   Cancel
  Delete tag   Cancel
  • • DevOps notes •
  •  
  • AI
  • Tags
  • Login

Shell Scripting Basics/shaare/wcZcmg

  • linux
  • linux

First Line of Script

  • #!/bin/bash → defines the shell interpreter

Comments

  • Use # for commenting

Common Elements

  • Commands: echo, cp, etc.
  • Statements: if, while, for
  • +x → make the script executable
  • Use absolute path to run: /home/userdir/myscript.bash

Variable Definition

a=hello
b=mytext
  • Usage:
echo "text1 $a"
echo "text2 $b"
  • Example:
a=$(hostname)
echo $a  # => myfirstlinux

Input / Output Variable

read myinputvariable
echo "name $myinputvariable"

If Else Statement

if [[ $count -eq 100 ]]; then
  echo "count is 100"
else
  echo "no"
fi

File Existence Check

if [[ -e /file.txt ]]; then
  echo "file exists"
fi
1 week ago Permalink
cluster icon
  • Linux filesystem : /boot -> Grub.cfg /root -> home of root /dev -> system device (mouse, keyboard) /etc -> configuration files /bin -> /usr/bin -> everyday user commands...
  • Navigating File System / Linux filetypes : ls -l → List pwd → Print working directory dr-xr-xr-x | directories -rw-r--r-- | file Linux File Types Symbol Type - Regular file d Dire...
  • System information, root recovery, environment variables, shortcuts : Finding System Information cat /etc/redhat-release → Red Hat version uname -a → Linux hostname, kernel, architecture dmidecode → hardware, BIOS, syst...
  • File Display Commands / Filters / Text Processing Input : File Display Commands cat → Show entire content cat -A → Show non-printable characters more → Paginate output less → Same as more but allows navigatio...
  • Disk usage, logging, shutdown, hostname : Disk and Memory Info df → disk partition info df -h → human-readable format du → size of file/directory free → memory info cat /proc/cpuinfo → CPU in...


(19)
Filter untagged links
Fold Fold all Expand Expand all Are you sure you want to delete this link? Are you sure you want to delete this tag? The personal, minimalist, super-fast, database free, bookmarking service by the Shaarli community