When writing a bash script with command line arguments, I use the following structure :
#!/bin/bash
set -e
extension=".fna.gz"
declare -A genomes_completeness
declare -a genomes
declare -a completeness
Help() {
echo "help message"
}
#set default values of variables and declare types
foo=bar
if [ $# -eq 0 ]
then
Help
exit
fi
while [[ $# -gt 0 ]]
do
case $1 in
-f | --foo) foo="$2"
shift 2;;
-b | --bar) bar="$2"
shift 2;;
-h | --help) Help; exit;;
-* | --*) unknown="$1"; echo -e "Unknown option: ${unknown}"; Help; exit 1;;
*) shift;;
esac
done
It works well and I was writing another one but stumbled upon this error when checking if the Help message was correctly showing up when executing the script with no argument or the help
flag:
bash /path/script.sh --help
+ extension=.fna.gz
+ declare -A genomes_completeness
+ declare -a genomes
+ declare -a completeness
+ '[' 1 -eq 0 ']'
+ '[[ 1' -gt 0 ']]'
/path/script.sh: line 28: [[ 1: command not found
After looking for an error for a while (hoho) I just copy-pasted the while ...
(that line only) of another script and it then worked.
I wrote the script entirely by hand on linux with nano, so I have no idea if I inserted a special character (and how). If there was a special character would it show with set -x
? What are the other possible sources of that error ?
I hope the question is asked correctly.
Typing ComposeSpaceSpace may insert a non-breaking space character. Commonly, the AltGr key is mapped to be "Compose".
Some systems also insert a non-breaking space if you type Shift + Space
On linux, setxkbmap -print
may show configuration and man 7 xkeyboard-config
has information about configuring non-breaking space input.