0

I tried creating a shortcut to easily change into some of my Windows partitions. After mounting them, some works fine, some not. Here's what happens.

My ~/.bash_aliases contains:

export geo=/media/geo/Novo\ volume/Geo
export windows=/media/geo/OS/Users/Geo

When I type in terminal

geo@george-Ubuntu:~$ cd $windows
geo@george-Ubuntu:/media/geo/OS/Users/Geo$ 

it works as expected.

However, when I try:

geo@george-Ubuntu:/media/geo/OS/Users/Geo$ cd $geo
bash: cd: /media/geo/Novo: No such file or directory

It can't find the directory (made sure that "Novo Volume" is mounted and the directory exists)

How can I fix this? Symbolic Link: No such file or directory Didn't help me.

3 Answers 3

2

You see:

bash: cd: /media/geo/Novo: No such file or directory

since you tried to set a variable for the folder "/media/geo/Novo volume/Geo" (with a space) and the error is about only the first part of the path up to the space, you see, that the space is wrongly treated as separator.

If you want to use

cd $geo

yuo could have to include the quotes in the string:

export geo='"/media/geo/Novo volume/Geo"'

which isn't a good solution, a better approach is to set an alias in your .bash_aliases for example:

alias cd-geo='cd "/media/geo/Novo volume/Geo"'
alias cd-windows='cd /media/geo/OS/Users/Geo'
2

All you need to do is quoting the variable, since it contains a space character.

cd "$geo"

Quoting variables which might contain spaces is always good practice in shell code.

1

Stolen from this SO question If you do cd "$geo" I'll bet you get the right result

That being said, try doing

alias geo="cd /media/geo/OS/Users/Geo" and then just using geo (as a command) to go there.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .