Skip to content

Instantly share code, notes, and snippets.

@crischutu07
Created July 3, 2023 15:21
Show Gist options
  • Save crischutu07/5f1bd44468147e21629802dc45ef00f8 to your computer and use it in GitHub Desktop.
Save crischutu07/5f1bd44468147e21629802dc45ef00f8 to your computer and use it in GitHub Desktop.
handle function arguments with read statements
#!/usr/bin/env bash
source cmdHandler.sh
echo 'hello'
function test (){
local args=$1
echo "Test args: $args"
}
while true; do
read -p "> " maininput
# only use the first args (group)
fixedinput=$(echo ${maininput%% *})
case "$(echo ${fixedinput})" in
[Tt]est) test "$maininput";;
[Ee]xit) exit;;
[Rr]estart) exit; bash '$0.sh';;
'');; # '' not found fix
[Aa]rgs) echo $fixedinput;;
*) echo "'$maininput' is not found";;
esac
done
@crischutu07
Copy link
Author

use for fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment