3

This is really confusing...

I currently have a Debian 8 computer, and I connect to it using PuTTY (SSH).
The default console used is Bash.

When I try to pass a path to an alias, it gives the following error:

 -bash: /: Is a directory

Here is an example:

putty

Also, there's a bizarre behaviour: running '/' or "/" cause the same error, as if Bash were ignoring quotes.


If it matters, the alias explorer was defined like this:

alias explorer='pcmanfm 1>/dev/null 2>&1 &'

Is this the expected behaviour?
If not, what am I doing wrong?

  • 1
    Also, there's a bizarre behaviour: running '/' or "/" cause the same error, as if Bash were ignoring quotes. - What are you expecting bash to do when you type '/'? – marcelm Jun 24 '16 at 22:00
  • @marcelm A syntax error, a warning or just displaying / (similar to echo). – Ismael Miguel Jun 24 '16 at 22:11
  • 1
    The syntax is fine so there is no syntax error, you do get a warning ("/: Is a directory"), and just displaying / would be inconsistent with anything else bash does. Try comparing the results of entering 'garply', 'ls', '/bin/ls', '/bin' and '/'? Also try them without the quotes; why would the quotes change the result? – marcelm Jun 24 '16 at 23:01
  • You might find this explanation of how quotes relate to argument lists helpful. Particularly the last paragraph. – Wildcard Jun 24 '16 at 23:27

2 Answers2

14

The way you wrote your alias, the command you run would be expanded as

pcmanfm 1>/dev/null 2>&1 & '/'

This will run pcmanfm without any options as a background job and then try to run / as a command.

You probably want a function instead of an alias

explorer() { pcmanfm "$@" >/dev/null 2>&1 & }
terdon
  • 242,166
  • But '/' is in single quotes. Why would Bash even attempt to run it? (I understand if it was with "/") – Ismael Miguel Jun 24 '16 at 17:00
  • 2
    '/foo/bar/baz' will try and run the command; the quotes here don't matter. – Stephen Harris Jun 24 '16 at 17:02
  • 10
    @IsmaelMiguel the quotes are irrelevant. The point is that the & is a list terminator so bash reads the next item (whatever that may be) as a command. – terdon Jun 24 '16 at 17:41
  • @terdon So, if I do echo 'a' & 'rm -rf /', it will nuke my system? – Ismael Miguel Jun 24 '16 at 19:37
  • Thank you a lot for the function. I really tried a function before, but, I couldn't do it. I am accepting this answer since it is the first one and provides a fix. – Ismael Miguel Jun 24 '16 at 19:38
  • 4
    @IsmaelMiguel no, 'rm -rf /' tries to run a command containing 8 characters. It's highly unlikely there is such a command so it will fail. On the other hand 'rm' '-rf' '/' will succeed in running the rm command with an instruction to (attempt to) remove the entire filesystem. – Chris Davies Jun 24 '16 at 19:43
  • @roaima That almost makes sense to me. But, that is an entirelly new question. Thank you a lot for explaining it to me. – Ismael Miguel Jun 24 '16 at 19:48
4

The alias provides a literal expansion. So running explorer / maps to

pcmanfm 1>/dev/null 2>&1 & /

This runs pcmanfm in the background, immediately followed by / in the foreground.

Chris Davies
  • 116,213
  • 16
  • 160
  • 287