bash script: if/while and function