I'm doing one of the courses on bash, which seems a bit outdated.I have a simple script below, which should allow me to see lines as they are read or executed, but my console gives nothing back. The $1 argument passed to bartek_report.sh is missing on purpose as I wanted to see what happens when the console hangs. Using the latest Ubuntu.

#!/bin/bash -v    #or -x   

# creates a report for a single container

# exercise: add a variable called 'directory'
# that determines where we save our output file


mkdir -p $directory
grep $1 shipments.csv > $directory/$1.csv
echo Report created in $directory under filename $1.csv

When I call the script under bash it just hangs like without -x or -v, why?

bartek@Lenovo-LAB~/Desktop/Devs/bash_learning/02/demos/after_m2$ sh bartek_report.sh
[blinking cursor]
  • would appreciate vote for close if the question is not good, or perhaps a comment of what is the feedback to consider going forward. as I learn I can only ask you to be supportive. Jan 30 at 15:52

You're not calling your script with bash, as you've explicitly named sh as the shell with which to run the script.

The top line #! is only considered when you make the script executable and treat it like any other program in the system

chmod a+x myscript    # Make executable
./myscript            # Run it

As has been mentioned in a comment below this answer, you should also note that neither -x nor -v write to stdout. Both are debugging tools and write their messages to stderr so as not to interrupt the flow of any valid normal output. (So ./script >file will leave the debugging messages written to your terminal, with the normal expected output being written to file.)

  • @steeldriver the OP already told you that. What should also be mentioned is that -x and -v write to stderr, not to stdout. Jan 30 at 15:51
  • $1 is empty on purpose Jan 30 at 15:53
  • @UncleBilly answer amended to include your suggestion, thank you
    – roaima
    Jan 30 at 18:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.