← Back to Upcase

Sign In to Upcase

© 2012 - 2016 thoughtbot, inc. Upcase, the design of a robot, and thoughtbot are registered trademarks of thoughtbot, inc.

This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/shell-scripting

I tried set -o pipefail in the shell script. When I execute the script. I get the following output:

./print-services.sh: 4: set: Illegal option -o pipefail

any idea what’s going on?

@serixscorpio On many systems, /bin/sh isn’t actually a standard sh. For example, on OSX, it’s symlinked to Bash. I suspect that you’re using something other than OSX (maybe a BSD?) that symlinks to something that doesn’t support set -o. (You can check this by running /bin/sh --version in your terminal and seeing what it says. Mine says GNU Bash and then a version.)

To fix your set -o issue, change #!/bin/sh at the top of the file to #!/bin/bash.

Thanks a lot man!

I made a bash function that checks for the presence of arguments, using the following block:

if [[  $# -eq 0 ]]; then 
  echo "Please provide an argument."
  exit 64

When I test my function with no arguments, the whole terminal (iTerm) window exits and closes all my tabs. That’s definitely not what happened in the video, so I’m not sure what’s amiss here. I’m definitely using bash, not sh, and I’m on MacOS Mojave.

Nevermind. I figured out that when using a function – not a script – I need to return [n] instead of exit [n]