how can i make this script actually change the directory i'm in?
so the script just takes some options from a database then after i select the one i want, it doesn't work i also tried running the script with source but still nothing..
#!/bin/bash
options=( $(mysql --skip-column-names -uroot -pmypass all_dbs -e "select path from databases_table WHERE locked != 0 ") )
read_list(){
echo ""
PS3="Change directory to:"
select opt in "${options[@]}" "Quit" ; do
if (( REPLY == 1 + ${#options[@]} )) ; then
exit
elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then
chosen="$opt"
break
else
echo "Invalid option. Try another one."
fi
done
}
changeto_entry(){
mysql -uroot -pmypass --skip-column-names all_dbs -e "select name,\`database\`,path from databases_table where locked != 0 AND name = '$chosen'" | while read name database path; do
cd $path
done
}
read_list
changeto_entry