How would I pass the 2nd argument into a bash function called setdb
?
I ask the user to enter a command. If the user enters setdb test
, I want to pass test into the function setdb
. Then I want to run a file test on it to see if test.txt exists.
#!/bin/bash
#Setdb. Checks if the file exist, read, does not exist,
setdb () {
if [[ -e $FILE && -r $FILE ]]; then
echo "Database set to" $FILE
elif [! -f $FILE && -w $FILE ]; then
touch datbase.txt
echo "File database created. Database set to database.txt"
fi
}
while read answer; do
if [[ $answer == "setdb" ]]; then
setdb
fi
done