I have a small function that I keep in my profile to give me quick access to some config files:

viconf () { COLUMNS=12; printf "Edit config file:\n\n"; select x in ~/.bashrc ~/.bash_profile ~/.bash_login ~/.profile ~/.inputrc ~/.vimrc; do vim $x; break; done } 

It creates output like this:

1) /home/boss/.bashrc 2) /home/boss/.bash_profile 3) /home/boss/.bash_login 4) /home/boss/.profile 5) /home/boss/.inputrc 6) /home/boss/.vimrc #? 

I'm not really happy with this. I want the #? to have a \n and then say Select a config file to edit with vi?. I've tried lots of ways to edit PS3 but everything I try fails to achieve this (specifically, the \n always fails). How do I make my function have a custom prompt?

1 Answer

You can either insert a literal newline in the string:

PS3=' Select a config file to edit with vi? ' 

or use printf with a C-style \n for the newline:

PS3="$(printf '\nSelect a config file to edit with vi? ')" 

or using the bash shell's printf -v to write to the variable directly

printf -v PS3 '\n%s ' 'Select a config file to edit with vi?' 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy