I am learning bash scripting and did some exercises on one PC, committed the files to my GitHub so I can continue from another device.
When I pulled the repo I tried my existing scripts and they didn't work as on the initial device (with WSL Ubuntu 20.04).
When running these from WSL Ubuntu 18.04 I am getting funny errors:
tymon@Tymon-PC:/mnt/f/Documents/GIT/Bash_course_udemy/Section2$ ll
total 0
drwxrwxrwx 1 tymon tymon 512 Feb 20 21:14 ./
drwxrwxrwx 1 tymon tymon 512 Feb 20 17:56 ../
-rwxrwxrwx 1 tymon tymon 157 Feb 20 21:19 conditionalStatement.sh*
-rwxrwxrwx 1 tymon tymon 237 Feb 20 17:56 conditionalWithElif.sh*
-rwxrwxrwx 1 tymon tymon 57 Feb 20 21:14 hi.py*
-rwxrwxrwx 1 tymon tymon 335 Feb 20 22:02 hostname.sh*
-rwxrwxrwx 1 tymon tymon 22 Feb 20 17:56 sleepy.sh*
-rwxrwxrwx 1 tymon tymon 276 Feb 20 17:56 variable.sh*
tymon@Tymon-PC:/mnt/f/Documents/GIT/Bash_course_udemy/Section2$ . hostname.sh
: command not found
!u are running this script on Tymon-PC
!ou are running this script on Tymon-PC
: command not found
Using back quote(`XVZ`) for variable instead:
!ou are running this script on Tymon-PC
!u are running this script on Tymon-PC
tymon@Tymon-PC:/mnt/f/Documents/GIT/Bash_course_udemy/Section2$
I checked permissions look correct, the bash path in the script is the same, but the result of the script on my Desktop is having errors and missing letters.
Example of the code:
#! /bin/bash
SERVER_NAME=$(hostname)
echo "You are running this script on $SERVER_NAME !"
echo "You are running this script on ${SERVER_NAME}!"
SERV_NAME=`hostname`
echo "Using back quote(\`XVZ\`) for variable instead:"
echo "You are running this script on ${SERV_NAME}!"
echo "You are running this script on $SERV_NAME !"
When I try to run this in VSC in WSL bash I can replicate:
tymon@Tymon-PC:/mnt/f/Documents/GIT/Bash_course_udemy/Section2$ . hostname.sh
: command not found
!u are running this script on Tymon-PC
!ou are running this script on Tymon-PC
: command not found
Using back quote(`XVZ`) for variable instead:
!ou are running this script on Tymon-PC
!u are running this script on Tymon-PC
tymon@Tymon-PC:/mnt/f/Documents/GIT/Bash_course_udemy/Section2$
If I switch to GIT bash the script runs fine:
Tymon@Tymon-PC MINGW64 /f/Documents/GIT/Bash_course_udemy/Section2
$ . hostname.sh
You are running this script on Tymon-PC !
You are running this script on Tymon-PC!
Using back quote(`XVZ`) for variable instead:
You are running this script on Tymon-PC!
You are running this script on Tymon-PC !
My question is:
- would the different versions of bash make the difference - I can see the bash has different versions between WSL and GIT bash: GIT Bash:
tymon@Tymon-PC MINGW64 /f/Documents/GIT/Bash_course_udemy/Section2
$ bash --version
GNU bash, version 5.2.12(1)-release (x86_64-pc-msys)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
WSL bash:
tymon@Tymon-PC:/mnt/f/Documents/GIT/Bash_course_udemy/Section2$ bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
is it possible that the pushing and pulling to GitHub broke the scripts?
I have tried to replicate it in different terminals (WSL, GCP, Git bash)
Tried re-create scripts on the affected device
Checked if the bash path provided in these scripts is correct
Checked if running bash hostname.sh or ./hostname.sh works
Tested if removing space from shebang would make a difference