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

viconf ()
    printf "Edit config file:\n\n";
    select x in ~/.bashrc ~/.bash_profile ~/.bash_login ~/.profile ~/.inputrc ~/.vimrc;
        vim $x;

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?


You can either insert a literal newline in the string:

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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.