Difference between revisions of "IT-SDK-Shell"
Jump to navigation
Jump to search
Samerhijazi (talk | contribs) (→File Test) |
Samerhijazi (talk | contribs) (→Examples) |
||
| Line 35: | Line 35: | ||
fi | fi | ||
done | done | ||
| + | #------------------------------------ | ||
| + | echo "$(date +%Y.%m.%d_%H:%M:%S) >>> Processing $VIN >>> $STATUS" | ||
| + | echo "$(date +%Y.%m.%d_%H:%M:%S) >>> Skipping $VIN >>> non-existent folder" | tee -a "ERROR-testdata-full.log" | ||
| + | #------------------------------------ | ||
| + | if unzip -t "$zip_path" >/dev/null 2>&1; then | ||
| + | echo " ➤ ZIP is valid." >> "$log_file" | ||
| + | else | ||
| + | echo " ⚠️ ZIP is corrupted or unreadable!" >> "$log_file" | ||
| + | fi | ||
| + | </pre> | ||
| + | |||
| + | <pre class="code"> | ||
| + | [ -z "$VIN" ] && continue # Skip empty lines | ||
| + | |||
| + | if [[ -f "$zip_path" ]]; then | ||
</pre> | </pre> | ||
Latest revision as of 09:22, 18 April 2025
Contents
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
#------------------------------------
echo "$(date +%Y.%m.%d_%H:%M:%S) >>> Processing $VIN >>> $STATUS"
echo "$(date +%Y.%m.%d_%H:%M:%S) >>> Skipping $VIN >>> non-existent folder" | tee -a "ERROR-testdata-full.log"
#------------------------------------
if unzip -t "$zip_path" >/dev/null 2>&1; then
echo " ➤ ZIP is valid." >> "$log_file"
else
echo " ⚠️ ZIP is corrupted or unreadable!" >> "$log_file"
fi
[ -z "$VIN" ] && continue # Skip empty lines if [[ -f "$zip_path" ]]; then
MIX
- https://www.bin-bash.de/scripts.html
- https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425
#!/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
File Test
if [ -s "file.txt" ]; then
echo "file.txt is not empty."
else
echo "file.txt is empty."
fi
| 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. |