Introduction to Bash Scripting
Difference between sh and bash
Last Updated : 21 Feb, 2022
bash and sh are two different shells of the Unix operating system. bash is sh, but with more features and better syntax. Bash is “Bourne Again SHell”, and is an improvement of the sh (original Bourne shell). Shell scripting is scripting in any shell, whereas Bash scripting is scripting specifically for Bash. sh is a shell command-line interpreter of Unix/Unix-like operating systems. sh provides some built-in commands. bash is a superset of sh. Shell is a command-line interface to run commands and shell scripts. Shells come in a variety of flavors, much as operating systems come in a variety of flavors. So, Shell is an interface between the user and the operating system, which helps the user to interact with the device.
refs: GeeksforGeeks (https://www.geeksforgeeks.org/difference-between-sh-and-bash/)
# Echo out the entire ARGV array
echo $@
# Echo out the size of ARGV
echo $#
# Create three variables from the temp data files' contents
temp_a=$(cat temps/region_A)
temp_b=$(cat temps/region_B)
temp_c=$(cat temps/region_C)
# Print out the three variables
echo "The three temperatures were $temp_a, $temp_b, and $temp_c"
array
# Create a normal array with the mentioned elements
capital_cities=("Sydney" "Albany" "Paris")
# The array has been created for you
capital_cities=("Sydney" "Albany" "Paris")
# Print out the entire array
echo ${capital_cities[@]}
# Print out the array length
echo ${#capital_cities[@]}
# An associative array has been created for you
declare -A model_metrics=([model_accuracy]=98 [model_name]="knn" [model_f1]=0.82)
# Print out just the keys
echo ${!model_metrics[@]}
IF
# Conditionally move into bad_models folder
if [ $accuracy -lt 90 ]; then
mv $1 bad_models/
for & while
# Use a FOR loop on files in directory
for file in inherited_folder/*.R
do
# Echo out each file
echo $file
done
# Create a FOR statement on files in directory
for file in robs_files/*.py
do
# Create IF statement using grep
if grep -q 'RandomForestClassifier' $file ; then
# Move wanted files to to_keep/ folder
mv $file to_keep/
fi
done
CASE
# Use a FOR loop for each file in 'model_out'
for file in model_out/*
do
# Create a CASE statement for each file's contents
case $(cat $file) in
# Match on tree and non-tree models
*"Random Forest"*|*GBM*|*XGBoost*)
mv $file tree_models/ ;;
*KNN*|*Logistic*)
rm $file ;;
# Create a default
*)
echo "Unknown model in $file" ;;
esac
done
Author And Source
이 문제에 관하여(Introduction to Bash Scripting), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@jee-9/Introduction-to-Bash-Scripting저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)