I have a bash script to set the keyboard type of my external and internal laptop keyboards (so as they are both usable and output the correct characters).
The main part of the script works fine, but I have a problem with the switch / case for capturing the command line options.
this is the full script
#!/bin/bash
###functions first
usage()
{
echo "script to set the internal and external keyboards to french and english repectively"
}
setKeyBoardMap()
{
echo "setting dual keyboard."
echo "setting keyboard types..."
setxkbmap -device 13 fr
setxkbmap -device 10 gb
echo "done"
}
##the main show
#capture command line parameters
if ["$1" = ""]; then
#no command line parameters
setKeyBoardMap
exit 0
else
while [ "$1" != " "]; do
case $1 in
-h | --help) usage
exit 1
;;
-*|--*)
echo "Unknown option $1"
echo "please use -h or --help for usage details"
exit 1
;;
#add any switches in here
#you may decide to modify this to set the keyboard
#according to your prefered type.
esac
done
fi
When I call this from my home directory I get the following
:~$ bash -x 2Keyb.sh -h
+ '[-h' = ']'
2Keyb.sh: line 31: [-h: command not found
+ '[' -h '!=' ' ]'
2Keyb.sh: line 37: [: missing `]'
I'm not sure what I'm missing but I'm sure it is in my while statement.
I know that having this construct for command line arguments is a bit excessive, but I plan to make this usable on any laptop to set the keybaord language between any 2.
But first I need to get it working as it.
If I don't pass any arguments the script functions perfectly...
Thanks in advance, your help is appreciated.
David