You are not logged in.

#1 2012-01-25 21:41:11

evil
Member
From: Indianapolis, IN
Registered: 2010-03-06
Posts: 41
Website

Issue: Bash function for .bashrc

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)


Site | Blog | Freenode Nick: i686

Offline

#2 2012-01-27 00:44:25

B-80
Member
Registered: 2010-05-05
Posts: 47

Re: Issue: Bash function for .bashrc

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

Board footer

Powered by FluxBB