Skip to main content
Question

getting an error executing a bash script

  • September 25, 2024
  • 8 replies
  • 0 views

TonyNelson
Forum|alt.badge.img+3

I'm getting the following error when running my script "[student: command not found
/Library/Application Support/JAMF/tmp/student profile". The script checks to see who is lpgged in, and if it is "student" it needs to change the user's profile pic". script below:

"#!/bin/sh

# determines current user
consoleUser=$( /usr/bin/stat -f%Su /dev/console )
if [$consoleUser == "student"]; then
dscl . create /Users/$consoleUser Picture "/Users/Shared/THS_Files/images/Howie.png"
fi
if [$consoleUser == "howardstudent"]; then
dscl . create /Users/$consoleUser Picture "/Users/Shared/THS_Files/images/Howie.png"
fi"

8 replies

AJPinto
Forum|alt.badge.img+26
  • Legendary Contributor
  • 2708 replies
  • September 25, 2024

try changing the interpreter from sh to bash.


TonyNelson
Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 6 replies
  • September 25, 2024
AJPinto wrote:

try changing the interpreter from sh to bash.


forgive me I'm new to Jamf, where would I do that?


Forum|alt.badge.img+11
  • Contributor
  • 126 replies
  • September 25, 2024
TonyNelson wrote:

forgive me I'm new to Jamf, where would I do that?


change the #!/bin/sh to #!/bin/bash


AJPinto
Forum|alt.badge.img+26
  • Legendary Contributor
  • 2708 replies
  • September 25, 2024
TonyNelson wrote:

forgive me I'm new to Jamf, where would I do that?


All is well. This is a script thing not a Jamf thing. The first line of a macOS script or any Unix script is called the shebang, that is where you specify the interpreter the script will use. Change that first line from #!/bin/sh to #!/bin/bash. You are currently using the sh interpreter; ideally you want to use bash or zsh and occasionally python3 with some osascript (Apple Script) from time to time. The shebang determines what "language" the script needs to be written in, and a script that works with one shebang will not necessarily work with another.

 

Try the code this way instead.

 

 

#!/bin/bash # determines current user consoleUser=$( /usr/bin/stat -f%Su /dev/console ) if [$consoleUser == "student"]; then dscl . create /Users/$consoleUser Picture "/Users/Shared/THS_Files/images/Howie.png" fi if [$consoleUser == "howardstudent"]; then dscl . create /Users/$consoleUser Picture "/Users/Shared/THS_Files/images/Howie.png" fi

 

 

 

 


TonyNelson
Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 6 replies
  • September 25, 2024
AJPinto wrote:

All is well. This is a script thing not a Jamf thing. The first line of a macOS script or any Unix script is called the shebang, that is where you specify the interpreter the script will use. Change that first line from #!/bin/sh to #!/bin/bash. You are currently using the sh interpreter; ideally you want to use bash or zsh and occasionally python3 with some osascript (Apple Script) from time to time. The shebang determines what "language" the script needs to be written in, and a script that works with one shebang will not necessarily work with another.

 

Try the code this way instead.

 

 

#!/bin/bash # determines current user consoleUser=$( /usr/bin/stat -f%Su /dev/console ) if [$consoleUser == "student"]; then dscl . create /Users/$consoleUser Picture "/Users/Shared/THS_Files/images/Howie.png" fi if [$consoleUser == "howardstudent"]; then dscl . create /Users/$consoleUser Picture "/Users/Shared/THS_Files/images/Howie.png" fi

 

 

 

 


Thanks but I still got the error.


sdagley
Forum|alt.badge.img+25
  • Jamf Heroes
  • 3532 replies
  • September 25, 2024
TonyNelson wrote:

Thanks but I still got the error.


@TonyNelson At a minimum you need a space after the [ and before the ] in your if statements. You should also take a look at https://www.shellcheck.net/ as a way to check for common errors in a shell script.


Forum|alt.badge.img+11
  • Contributor
  • 126 replies
  • September 25, 2024
sdagley wrote:

@TonyNelson At a minimum you need a space after the [ and before the ] in your if statements. You should also take a look at https://www.shellcheck.net/ as a way to check for common errors in a shell script.


wow, shell check sure is neat. may install that locally, thanks for posting that. 

after editing the script in shell check, this one seemed to work.

 

#!/bin/bash # determines current user consoleUser=$( /usr/bin/stat -f%Su /dev/console ) if [ "$consoleUser" == "student" ]; then dscl . create /Users/"$consoleUser" Picture "/Users/Shared/THS_Files/images/Howie.png" fi if [ "$consoleUser" == "howardstudent" ]; then dscl . create /Users/"$consoleUser" Picture "/Users/Shared/THS_Files/images/Howie.png" fi

 


TonyNelson
Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 6 replies
  • September 25, 2024
sdagley wrote:

@TonyNelson At a minimum you need a space after the [ and before the ] in your if statements. You should also take a look at https://www.shellcheck.net/ as a way to check for common errors in a shell script.


Thanks, and Plus one about shellCheck.  However I must be missing something as the script ran with no errors but the profile picutre still didn't change.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings