Home > Software engineering >  How to use spaces and symbols in bashrc
How to use spaces and symbols in bashrc

Time:10-02

I have some config files saved to my google drive and I want to source them in my bash init files (I use .bashrc).

The most recent version of Google drive prefaces your drive with your gmail address and spaces. As in "[email protected] - Google Drive/ My Drive". I'd like to save this address in a variable that I could use downstream in .bashrc. Extra points if I can cd $GDRIVE in the interactive shell as well, but I really care about the config files.

The relevant lines in my file look like this

GDRIVE1="~/myname\@gmail.com\ -\ Google\ Drive/My\ Drive"
GDRIVE2="\"~/[email protected] - Google Drive/My Drive\""

GDRIVE=$GDRIVE2

# Import alias definitions.
if [ -f "$GDRIVE"/Sysadmin/ConfigFiles/.bash_aliases ]; then
    . ~/Google\ Drive/Sysadmin/ConfigFiles/.bash_aliases
else
    echo "Could not find bash alias file."
fi

GDRIVE1 and GDRIVE2 are just there to illustrate things I've tried.

CodePudding user response:

A tilde only expands to your home directory if it's unquoted. It needs to be outside of double quotes. Meanwhile you can leave the spaces unescaped as long as they are quoted.

GDRIVE=~/"[email protected] - Google Drive/My Drive"
  •  Tags:  
  • bash
  • Related