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 month ago Permalink
cluster icon
  • User management : Essential Commands: useradd, groupadd, userdel, groupdel, usermod Modify 3 files: /etc/passwd, /etc/group, /etc/shadow Create User with Custom O...
  • Linux File Ownership, ACLs, and I/O Redirects : File Ownership chown → Change ownership chgrp → Change group Access Control List (ACL) setfacl → Set file ACL getfacl → Get file ACL Add Permissi...
  • 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...
  • Screen & Tmux : Screen (Terminal Multiplexer) Multi-terminal sessions in one window Alt+A | → split vertical Alt+A Shift+S → split horizontal Alt+A Tab → switch wind...
  • Systemctl, process management : Basic System Info Commands uptime → time, uptime, users, load average hostname → current hostname ip hostname → show IP & hostname uname -a → current...


(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