IT-SDK-Shell

From wiki.samerhijazi.net
Revision as of 22:16, 27 November 2024 by Samerhijazi (talk | contribs) (Variablen)
Jump to navigation Jump to search

Ref.

Setting

echo $SHELL           ### To determine which shell you are currently using in the Terminal.
ps -p $$ -o comm=     ### Will display the name of the current shell process.   
which bash
--------------------------------------------
ll /opt/homebrew/bin/bash -> ../Cellar/bash/5.2.15/bin/bash
sudo bash -c 'echo /opt/homebrew/bin/bash >> /etc/shells'
chsh -s /opt/homebrew/bin/bash

Examples

#!/bin/bash
 
read -p "How many Pods: " pods
if [[ $pods =~ [^0-9] ]]
    then
        echo "Sorry integers only"
fi
if [ -z "$pods" ]
    then
        pods=1
fi
echo "Setting Pods to ${pods}."
#------------------------------------
for file in "${TESTDATA[@]}"; do
    cp -r ./"${file}" ./${file%.csv}.prod
    if [ $? -eq 0 ]; then
        echo "Copied $file successfully"
    else
        echo "Error copying $file"
    fi
done

MIX

#!/bin/bash -euxo pipefail    ### 
set -e                        ### The option instructs bash to immediately exit if any command has a non-zero exit status.
set -u                        ### The option reference to any variable you haven't previously defined (with the exceptions of * and @) is an error, and causes the program to immediately exit.   
set -x                        ### Enables a mode of the shell where all executed commands are printed to the terminal.
set -o pipefail               ### This setting prevents errors in a pipeline from being masked.

Variablen

data_files=("file1.txt" "file2.txt" "file3.txt")
declare -x data_files
zip filename.zip "${data_files[$@]}"

xx

Option Description -b Returns true if the file exists and is a block special file. -c Returns true if the file exists and is a character special file. -d Returns true if the file exists and is a directory. -e Returns true if the file exists (any type: file, directory, etc.). -f Returns true if the file exists and is a regular file (not a directory or special file). -g Returns true if the file exists and has the set-group-ID flag set. -h or -L Returns true if the file exists and is a symbolic link. -k Returns true if the file exists and has the sticky bit set. -p Returns true if the file exists and is a named pipe (FIFO). -r Returns true if the file exists and is readable by the current user. -s Returns true if the file exists and has a size greater than zero (i.e., it is not empty). -t Returns true if the file descriptor is open and refers to a terminal (useful for stdin/stdout). -u Returns true if the file exists and has the set-user-ID flag set. -w Returns true if the file exists and is writable by the current user. -x Returns true if the file exists and is executable by the current user. -O Returns true if the file exists and is owned by the current user. -G Returns true if the file exists and its group matches the user's group. -N Returns true if the file exists and has been modified since it was last read.