|~~#3~~| pwd; ls | |~~#~~| cd Desktop && ls | |~~#~~| ping put.poznan.pl \\ //Ctrl+Z// \\ jobs \\ fg \\ //Ctrl+C// | |~~#~~| ping put.poznan.pl & \\ # that command will spam the screen with its results, but the shell still normally accepts commands \\ jobs \\ fg \\ //Ctrl+Z// \\ bg | |~~#~~| echo $VAR \\ VAR=text \\ echo $VAR | |~~#~~| OTHER=$VAR \\ echo $OTHER | |~~#~~| SIZE=5 \\ echo "The file size is ${SIZE}MB" | |~~#11~~| #!/bin/sh \\ echo "First arg: $1" \\ echo "Third arg: $3" | |~~#~~| #!/bin/sh \\ echo "This script has been called as $0 and has $# arguments." | |~~#~~|LANG=ja_JP.UTF-8 \\ date \\ vim \\     :q \\ LANG=de_DE.UTF-8 \\ rm -rf /root/.ssh/nope \\ lscpu| |~~#~~|PS1="\w> " \\ PS1="\[\e[1;30m\][\[\e[33m\]\u\[\e[30m\]@\[\e[34m\]\h\[\e[0;1m\] \w\[\e[30m\]]\$\[\e[0m\] " \\ # (There are plenty prompt generators in the Internet) | |~~#~~|lspci \\ PATH="/sbin:/usr/sbin:$PATH" \\ lspci| |~~#~~|X=42 \\ Y=42 \\ X=$%%(%%(X+1)) \\ Y=$%%(%%(Y+2)) \\ Z=$%%(%%(X*Y)) \\ echo $%%(%%(Z%128))| |:::|# You may also abuse the syntax and run:   echo $%%(%%(X=43, Y=42, X=X+1, Y=Y+2, Z=X*Y, Z%128))| |~~#~~| echo "In the current directory there are $(ls %%|%% wc -l) files" | |~~#~~|pstree -au > processes_$(date +%H_%M_%S).log| |~~#~~|START=$(date +%s%N); sleep 1; END=$(date +%s%N); echo $%%(%%(END-START))| |~~#~~|alias year="cal -my" \\ year 2025| ~~Exercise.#21~~ #!/bin/sh echo "What is your name:" read NAME echo "Hello $NAME!" ~~Exercise.#~~ #!/bin/sh read ONE TWO echo $((ONE+TWO)) ~~Exercise.#~~ [ -d dirname ] && cd dirname X=1 Y=2 [ "$X" -gt "$Y" ] || echo "Y≥X" ~~Exercise.#~~ if rm filename then echo "Removed the file" else echo "Failed to remove the file" fi ~~Exercise.#~~ #!/bin/sh if [ $# -ne 2 ] then echo "Wrong number of arguments" exit 1 fi if [ "$1" -le "$2" ] then : else # notice that 'else' branch is executed also for non-number arguments; [ "$1" -gt "$2" ] would fail for non-numeric arguments echo "the first argument must be lesser then or equal to the second argument" exit 1 fi ~~Exercise.#~~ #!/bin/sh case "$1" in *.pdf) pdftotext "$1" -;; *.zip) unzip -l "$1";; *) cat "$1";; esac ~~Exercise.#~~ #!/bin/sh for VAR in "$@" # 'in "$@"' can be left out, as "$@" is the default argument list for the for loop do echo "=== $VAR ===" head -n1 "$VAR" tail -n1 "$VAR" done ~~Exercise.#~~ #!/bin/sh for POW in $(seq ${1:-20}) do echo "2**$POW=$((2**POW))" done ~~Exercise.#~~ #!/bin/sh E=1 V=2 while ((V<${1:-10000})) do echo "2**$E=$V" V=$((V*2)) E=$((E+1)) done ~~Exercise.#~~ #!/bin/sh NUM=0 while [ -e myProg_$NUM.log ] do NUM=$((NUM+1)) done LOG=myProg_$NUM.log date > $LOG ~~Exercise.#~~
user@host ~ $ myFunction(){ echo "Hello world!"; }
user@host ~ $ myFunction
Hello world!
~~Exercise.#~~
user@host ~ $ repeatText(){ for I in $(seq $1); do echo "$2"; done; }
user@host ~ $ repeatText 3 "Example text."
Example text.
Example text.
Example text.
~~Exercise.#~~ myTree(){ ls -A "$1" 2>/dev/null | while read F do echo "$2$F" [ ! -L "$1/$F" -a -d "$1/$F" ] && myTree "$1/$F" " $2" done } ~~Exercise.#~~
user@host ~ $ trap "fortune" INT
user@host ~ $ ^C
Falling rock.
user@host ~ $
~~Exercise.#~~ #!/bin/sh TEMPFILE=$(mktemp) trap "echo \"Cleaning up the temporary file $TEMPFILE\"; rm $TEMPFILE" exit echo "Created a temporary file $TEMPFILE" date > "$TEMPFILE" sleep 12s date >> "$TEMPFILE" ~~META: language = en ~~