Skip to main content
replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
Source Link

Make sure that the script is executable, and run the script by just typing the command, including its path. For example, if the script is called foo and is in the current directory, run

./foo

Given the error message, you are doing something like sh foo. This runs the script under sh, not bash. sh on your machine is a different shell, probably dash, which doesn't support the for loop syntax you used. By running ./foo, your script will be executed by the shell mentioned in the first line, which is bash.

Your script is weird in several places:

or

    for x in "$@"; do
      count_lines "$x"
    done
  • I'm not sure what you're trying to do with title=$(grep -oPm1 "(?<=<title>)[^<]+" <<< "$0"); "$0" is the path to the script, so you're searching the regexp (?<=<title>)[^<]+ in the path to the script, which doesn't make much sense.

Make sure that the script is executable, and run the script by just typing the command, including its path. For example, if the script is called foo and is in the current directory, run

./foo

Given the error message, you are doing something like sh foo. This runs the script under sh, not bash. sh on your machine is a different shell, probably dash, which doesn't support the for loop syntax you used. By running ./foo, your script will be executed by the shell mentioned in the first line, which is bash.

Your script is weird in several places:

or

    for x in "$@"; do
      count_lines "$x"
    done
  • I'm not sure what you're trying to do with title=$(grep -oPm1 "(?<=<title>)[^<]+" <<< "$0"); "$0" is the path to the script, so you're searching the regexp (?<=<title>)[^<]+ in the path to the script, which doesn't make much sense.

Make sure that the script is executable, and run the script by just typing the command, including its path. For example, if the script is called foo and is in the current directory, run

./foo

Given the error message, you are doing something like sh foo. This runs the script under sh, not bash. sh on your machine is a different shell, probably dash, which doesn't support the for loop syntax you used. By running ./foo, your script will be executed by the shell mentioned in the first line, which is bash.

Your script is weird in several places:

or

    for x in "$@"; do
      count_lines "$x"
    done
  • I'm not sure what you're trying to do with title=$(grep -oPm1 "(?<=<title>)[^<]+" <<< "$0"); "$0" is the path to the script, so you're searching the regexp (?<=<title>)[^<]+ in the path to the script, which doesn't make much sense.
Source Link
Gilles 'SO- stop being evil'
  • 866.1k
  • 205
  • 1.8k
  • 2.3k

Make sure that the script is executable, and run the script by just typing the command, including its path. For example, if the script is called foo and is in the current directory, run

./foo

Given the error message, you are doing something like sh foo. This runs the script under sh, not bash. sh on your machine is a different shell, probably dash, which doesn't support the for loop syntax you used. By running ./foo, your script will be executed by the shell mentioned in the first line, which is bash.

Your script is weird in several places:

or

    for x in "$@"; do
      count_lines "$x"
    done
  • I'm not sure what you're trying to do with title=$(grep -oPm1 "(?<=<title>)[^<]+" <<< "$0"); "$0" is the path to the script, so you're searching the regexp (?<=<title>)[^<]+ in the path to the script, which doesn't make much sense.