You are not logged in.
Pages: 1
EDIT: Ok, just ported it outside of .bashrc and it seems to work just fine outside of .bashrc.. anyone know the reason why?
For some reason this code will work once, then it wont.. its like the custom_editor isn't getting filled.. i cannot seem to figure it out. If I close the terminal and re-run then it works.. but again, only that one time until I close and reopen
function brc() {
custom_editor=''
backup=0
while getopts ":e:b" FLAG;
do
case $FLAG in
e) custom_editor=$OPTARG ;;
b) backup=1 ;;
\?) return 1 ;;
*) echo $OPTARG ;;
esac
done
# [[ $custom_editor == '' ]] && custom_editor='nano --nowrap'
if [[ $backup == 1 ]]; then
\cp "${HOME}/.bashrc" "${HOME}/.bashrc_backup"
echo "brc: .bashrc backed up to ${HOME}/.bashrc_backup"
fi
$custom_editor "${HOME}/.bashrc"
}
Last edited by evil (2012-01-25 21:57:14)
Offline
add:
local OPTIND
to the top of the function. It's not going to be "regenerated" after the first call because it's global. Your indexes are getting messed up because you are not spawning a new instance of shell to run the script and that is the criteria for OPTIND to be set to index 1.
Last edited by B-80 (2012-01-27 00:59:35)
Offline
Pages: 1