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?

4
  • 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
    Commented Jun 24, 2016 at 22:00
  • @marcelm A syntax error, a warning or just displaying / (similar to echo). Commented Jun 24, 2016 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
    Commented Jun 24, 2016 at 23:01
  • You might find this explanation of how quotes relate to argument lists helpful. Particularly the last paragraph.
    – Wildcard
    Commented Jun 24, 2016 at 23:27

2 Answers 2

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 & }
7
  • But '/' is in single quotes. Why would Bash even attempt to run it? (I understand if it was with "/") Commented Jun 24, 2016 at 17:00
  • 2
    '/foo/bar/baz' will try and run the command; the quotes here don't matter. Commented Jun 24, 2016 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
    Commented Jun 24, 2016 at 17:41
  • @terdon So, if I do echo 'a' & 'rm -rf /', it will nuke my system? Commented Jun 24, 2016 at 19:37
  • 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. Commented Jun 24, 2016 at 19:43
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.

8
  • That addresses the explorer /, but not the quoted /. But it is still correct. Commented Jun 24, 2016 at 19:39
  • 1
    @IsmaelMiguel '/' is identical to /. What is there to explain? Commented Jun 24, 2016 at 19:41
  • That they are identical? Commented Jun 24, 2016 at 19:44
  • @IsmaelMiguel why do you expect them to be different?
    – Random832
    Commented Jun 24, 2016 at 19:55
  • 1
    @IsmaelMiguel nothing, really, it depends on how it is presented to the shell. That does deserve it's own question though.
    – terdon
    Commented Jun 24, 2016 at 22:22

You must log in to answer this question.

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