Skip to content

Commit e081df8

Browse files
committed
Updated script according to ShellCheck.
1 parent b9252cf commit e081df8

10 files changed

+50
-50
lines changed

scripts_data/interactive2.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ echo "Please, input second value to sum and press 'Enter'"
1010

1111
read -r V2
1212

13-
echo "Sum of two numbers $V1 and $V2 is $(("V1" + "V2"))."
13+
echo "Sum of two numbers ${V1} and ${V2} is $(("V1" + "V2"))."
1414

1515
# $ is unnecessary on arithmetic variables
1616

scripts_data/interactive2functions.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ function checkinput {
1111
while :
1212
do # Star of the body of the cycles
1313
read -r INPUT # Here the input from keyboard is received
14-
if [[ $INPUT =~ $NUMBER ]]; then # Test if $INPUT is a number
15-
echo "OK, input value is $INPUT."
14+
if [[ ${INPUT} =~ ${NUMBER} ]]; then # Test if $INPUT is a number
15+
echo "OK, input value is ${INPUT}."
1616
break # We have correct value, we can break the cycle and continue
1717
else # What to do if the user did not provide correct value
1818
echo "Error! You provided wrong value!" # Tell the user
@@ -24,18 +24,18 @@ function checkinput {
2424
echo "Please, input first value to sum and press 'Enter'"
2525
# Use the function to read the input
2626
checkinput
27-
V1=$INPUT
27+
V1="${INPUT}"
2828

2929
# Start of while cycles - run until correct input is provided
3030

3131
echo "Please, input second value to sum and press 'Enter'"
3232
# Use the function to read the input
3333
checkinput
34-
V2=$INPUT
34+
V2="${INPUT}"
3535

3636
echo
3737

38-
echo "Sum of two numbers $V1 and $V2 is $(("V1" + "V2"))."
38+
echo "Sum of two numbers ${V1} and ${V2} is $(("V1" + "V2"))."
3939

4040
echo
4141

scripts_data/interactive2whiles.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ echo "Please, input first value to sum and press Enter"
1212
while :
1313
do # Star of the body of the cycles
1414
read -r V1 # Here the input from keyboard is received
15-
if [[ $V1 =~ $NUMBER ]]; then # Test if V1 is a number
16-
echo "OK, input value is $V1."
15+
if [[ ${V1} =~ ${NUMBER} ]]; then # Test if V1 is a number
16+
echo "OK, input value is ${V1}."
1717
break # We have correct value, we can break the cycle and continue
1818
else # What to do if the user did not provide correct value
1919
echo "Error! You provided wrong value!" # Tell the user
@@ -27,8 +27,8 @@ echo "Please, input second value to sum and press Enter"
2727
while :
2828
do # Star of the body of the cycles
2929
read -r V2 # Here the input from keyboard is received
30-
if [[ $V2 =~ $NUMBER ]]; then # Test if V2 is a number
31-
echo "OK, input value is $V2."
30+
if [[ ${V2} =~ ${NUMBER} ]]; then # Test if V2 is a number
31+
echo "OK, input value is ${V2}."
3232
break # We have correct value, we can break the cycle and continue
3333
else # What to do if the user did not provide correct value
3434
echo "Error! You provided wrong value!" # Tell the user
@@ -38,7 +38,7 @@ while :
3838

3939
echo
4040

41-
echo "Sum of two numbers $V1 and $V2 is $(("V1" + "V2"))."
41+
echo "Sum of two numbers ${V1} and ${V2} is $(("V1" + "V2"))."
4242

4343
echo
4444

scripts_data/interactive4.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ if [ "$#" -ne "3" ]; then
1919

2020
# "=~" means we are testing if $1 fits to regular expression in $NUMBER
2121
# Is parameter 1 number?
22-
if [[ ! $1 =~ $NUMBER ]]; then
22+
if [[ ! $1 =~ ${NUMBER} ]]; then
2323
echo "Parameter 1 is not an integer!"
2424
usagehelp # The function to print help
2525
fi
2626

2727
# Is parameter 3 number?
28-
if [[ ! $3 =~ $NUMBER ]]; then
28+
if [[ ! $3 =~ ${NUMBER} ]]; then
2929
echo "Parameter 3 is not an integer!"
3030
usagehelp # The function to print help
3131
fi

scripts_data/interactive5.sh

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# All provided values are evaluated in while cycles...
44
while getopts "hvi:o:a:" INITARGS; do
5-
case "$INITARGS" in # $INITARGS contains the parameters to evaluate
5+
case "${INITARGS}" in # $INITARGS contains the parameters to evaluate
66
h|v) # Accept parameters "-h" or "-v" for help
77
echo "The script reads input text file and writes it given number of times into output text file." # What will be done it this is selected...
88
echo -e "\t\"-h\" or \"-v\" for this help"
@@ -13,19 +13,19 @@ while getopts "hvi:o:a:" INITARGS; do
1313
exit # Terminate after providing help
1414
;; # End of this option
1515
i) # Parameter "-i" accepts some value (e.g. "-i inputfile.txt")
16-
if [ -r "$OPTARG" ]; then # Check if the input file exists and is readable
17-
echo "OK, File \"$OPTARG\" exists and is readable. Proceeding..."
18-
INPUTFILE="$OPTARG" # $OPTARG always contains value of parameter
16+
if [ -r "${OPTARG}" ]; then # Check if the input file exists and is readable
17+
echo "OK, File \"${OPTARG}\" exists and is readable. Proceeding..."
18+
INPUTFILE="${OPTARG}" # $OPTARG always contains value of parameter
1919
else
20-
echo "Error! File \"$OPTARG\" doesn't exist or isn't readable!"
20+
echo "Error! File \"${OPTARG}\" doesn't exist or isn't readable!"
2121
echo
2222
exit 1
2323
fi
2424
;; # End of this option
2525
o) # Parameter "-o" accepts some value (e.g. "-o outputfile.txt")
26-
if [ -n "$OPTARG" ]; then # Check if there is some name for output variable
27-
echo "OK, Name for output file was provided: \"$OPTARG\". Proceeding..."
28-
OUTPUTFILE="$OPTARG" # $OPTARG always contains value of parameter
26+
if [ -n "${OPTARG}" ]; then # Check if there is some name for output variable
27+
echo "OK, Name for output file was provided: \"${OPTARG}\". Proceeding..."
28+
OUTPUTFILE="${OPTARG}" # $OPTARG always contains value of parameter
2929
else
3030
echo "Error! No output file name provided!"
3131
echo
@@ -34,15 +34,15 @@ while getopts "hvi:o:a:" INITARGS; do
3434
;; # End of this option
3535
a) # Parameter "-a" accepts some value (e.g. "-a X" for number)
3636
# Check if provided value makes sense (integer between 10 and 300)
37-
if [[ "$OPTARG" =~ ^[0-9]+$ ]] && [ "$OPTARG" -ge 10 ] && [ "$OPTARG" -le 300 ]; then # The condition is long...
38-
VALUE=$OPTARG # $OPTARG always contains value of parameter
39-
echo "Value is OK: $VALUE"
37+
if [[ "${OPTARG}" =~ ^[0-9]+$ ]] && [ "${OPTARG}" -ge 10 ] && [ "${OPTARG}" -le 300 ]; then # The condition is long...
38+
VALUE=${OPTARG} # $OPTARG always contains value of parameter
39+
echo "Value is OK: ${VALUE}"
4040
else
4141
echo "Error! For parameter \"-a\" you did not provide an integer ranging from 10 to 300!"
4242
exit 1
4343
fi
4444
;; # End of this option
45-
?)
45+
*)
4646
echo "Invalid option(s)!"
4747
echo "See \"$0 -h\" for usage options."
4848
exit 1
@@ -52,23 +52,23 @@ done
5252

5353
# Check if all required values are provided
5454

55-
if [ -z "$INPUTFILE" ] || [ -z "$OUTPUTFILE" ]; then
55+
if [ -z "${INPUTFILE}" ] || [ -z "${OUTPUTFILE}" ]; then
5656
echo "Error! Name of input and/or output file was not provided!"
5757
echo "See \"$0 -h\" for help usage..."
5858
echo
5959
exit 1
6060
fi
6161

62-
if [ -z "$VALUE" ]; then
62+
if [ -z "${VALUE}" ]; then
6363
echo "Warning! Value for \"-a\" was not provided! Using default value of 10."
6464
VALUE=10
6565
fi
6666

6767
# Do the job...
68-
for I in $(seq 1 $VALUE); do # Repeat task given number of times ($VALUE x)
69-
echo -ne "Cycle $I...\r" # Write number of cycle and return cursor to the beginning of the line to overwrite the number in next step
68+
for I in $(seq 1 "${VALUE}"); do # Repeat task given number of times ($VALUE x)
69+
echo -ne "Cycle ${I}...\r" # Write number of cycle and return cursor to the beginning of the line to overwrite the number in next step
7070
sleep 1s # Wait 1 second - just for fun ;-)
71-
cat "$INPUTFILE" >> "$OUTPUTFILE" # Do the task - append input to the output - note usage of variables
71+
cat "${INPUTFILE}" >> "${OUTPUTFILE}" # Do the task - append input to the output - note usage of variables
7272
done
7373

7474
echo -ne "\n" # Reset cursor to new line

scripts_data/metacentrum.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88

99
# Set data directories
1010
WORKDIR="my_data_dir" # Or something else
11-
DATADIR="/storage/praha1/home/$LOGNAME" # Or other storage
11+
DATADIR="/storage/praha1/home/${LOGNAME}" # Or other storage
1212

1313
# There is directory /storage/praha1/home/$LOGNAME/my_data_dir (in this case) containing all the data needed for calculations
1414

1515
# Clean-up of SCRATCH (it is temporal directory created by server) - the commands will be launched on the end when the job is done
1616
trap 'clean_scratch' TERM EXIT
17-
trap 'cp -a "$SCRATCHDIR" "$DATADIR"/ && clean_scratch' TERM
17+
trap 'cp -a "${SCRATCHDIR}" "${DATADIR}"/ && clean_scratch' TERM
1818

1919
# Prepare the task - copy all needed files from working directory into particular computer which will finally do the calculations
20-
cp -a "$DATADIR"/"$WORKDIR"/* "$SCRATCHDIR"/ || exit 1 # If it fails, exit script
20+
cp -a "${DATADIR}"/"${WORKDIR}"/* "${SCRATCHDIR}"/ || exit 1 # If it fails, exit script
2121

2222
# Change working directory - script goes to the directory where calculations are done
23-
cd "$SCRATCHDIR"/ || exit 1 # If it fails, exit script
23+
cd "${SCRATCHDIR}"/ || exit 1 # If it fails, exit script
2424

2525
# Prepare calculations - load required application modules
2626
# See https://wiki.metacentrum.cz/wiki/Kategorie:Applications
@@ -34,7 +34,7 @@ module add mrbayes-3.2.6
3434
find . -name "*.nexus" -print | parallel -j 8 'mb {} | tee -a {}.log'
3535

3636
# Copy results back to home directory
37-
cp -a "$SCRATCHDIR" "$DATADIR"/"$WORKDIR" || export CLEAN_SCRATCH=false
37+
cp -a "${SCRATCHDIR}" "${DATADIR}"/"${WORKDIR}" || export CLEAN_SCRATCH=false
3838

3939
# This is all needed, the script is ready to be launched...
4040

scripts_data/metacentrum_oxalis.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@
88

99
# FIXME Set data directories - modify for particular user
1010
DATAFSA='oxalis_assembly_6235.aln.fasta'
11-
DATADIR="/storage/praha1/home/$LOGNAME"
11+
DATADIR="/storage/praha1/home/${LOGNAME}"
1212

1313
# Clean-up of SCRATCH (it is temporal directory created by server)
1414
trap 'clean_scratch' TERM EXIT
15-
trap 'cp -a "$SCRATCHDIR" "$DATADIR"/ && clean_scratch' TERM
15+
trap 'cp -a "${SCRATCHDIR}" "${DATADIR}"/ && clean_scratch' TERM
1616

1717
# Required modules
1818
echo "Loading module(s)"
1919
module add iqtree-1.6.12 || exit 1 # iqtree
2020
echo
2121

2222
# Change working directory
23-
echo "Going to working directory $SCRATCHDIR"
24-
cd "$SCRATCHDIR"/ || exit 1
23+
echo "Going to working directory ${SCRATCHDIR}"
24+
cd "${SCRATCHDIR}"/ || exit 1
2525
echo
2626

2727
# Copy data
2828
echo "Copying..."
29-
echo "Data file - $DATAFSA"
30-
cp -a "$DATADIR"/"$DATAFSA" "$SCRATCHDIR"/ || exit 1
29+
echo "Data file - ${DATAFSA}"
30+
cp -a "${DATADIR}"/"${DATAFSA}" "${SCRATCHDIR}"/ || exit 1
3131
echo
3232

33-
echo "Computing gene tree from $DATAFSA..."
34-
iqtree -s "$DATAFSA" -st DNA -nt 1 -m MFP+I+R+P -lmap ALL -cmax 1000 -nstop 1000 -alrt 10000 -bb 10000 -bnni || exit 1
33+
echo "Computing gene tree from ${DATAFSA}..."
34+
iqtree -s "${DATAFSA}" -st DNA -nt 1 -m MFP+I+R+P -lmap ALL -cmax 1000 -nstop 1000 -alrt 10000 -bb 10000 -bnni || exit 1
3535
echo
3636

3737
# Copy results back to home directory
3838
echo "Copying data back"
39-
cp -a "$SCRATCHDIR" "$DATADIR"/ || export CLEAN_SCRATCH='false'
39+
cp -a "${SCRATCHDIR}" "${DATADIR}"/ || export CLEAN_SCRATCH='false'
4040

4141
exit

scripts_data/noninteractive.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Simple non-interactive script - no communication with user only list of commands - prints user name, date and $PATH
44

5-
echo "Hi, $USER, today is $(date) and your PATH is $PATH."
5+
echo "Hi, ${USER}, today is $(date) and your PATH is ${PATH}."
66

77
echo
88

scripts_data/raxml_case.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ INPUT="$1" # Specification of input file
77
# Determine which CPU is available and which binary use then
88
CPUFLAGS=$(grep -i flags /proc/cpuinfo | uniq)
99

10-
case "$CPUFLAGS" in
10+
case "${CPUFLAGS}" in
1111
*avx2*|*AVX2*) # Does the CPU support AVX2?
1212
RAXML='raxmlHPC-AVX2' # Select appropriate binary
1313
;;
@@ -23,8 +23,8 @@ case "$CPUFLAGS" in
2323
esac # End of branching
2424

2525
# Tell us the result
26-
echo "Using $RAXML binary."
26+
echo "Using ${RAXML} binary."
2727

28-
"$RAXML" -s "$INPUT" # All the parameters as usually...
28+
"${RAXML}" -s "${INPUT}" # All the parameters as usually...
2929

3030
exit

scripts_data/raxml_if.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ if grep -iq avx2 /proc/cpuinfo; then # Does the CPU support AVX2?
1616
fi # End of branching
1717

1818
# Tell us the result
19-
echo "Using $RAXML binary."
19+
echo "Using ${RAXML} binary."
2020

21-
"$RAXML" -s "$INPUT" # All the parameters as usually...
21+
"${RAXML}" -s "${INPUT}" # All the parameters as usually...
2222

2323
exit

0 commit comments

Comments
 (0)