confused with BASH shell in Redhat

Discussion in 'Linux Networking' started by Ka, Aug 22, 2003.

  1. Ka

    Ka Guest

    I tried download a file with ncftpget,
    and then the dir name is "-=New Game=-"

    ls -al

    drwxr-xr-x 3 root root 4096 Aug 22 19:19 -=New Game=-

    so, now I can not use command cd and du, :-((
    I am confused with Bash, why ?
    the shell expands my input, if I use key "tab", as following:

    [[email protected] ]# cd -\=New\ Game\=-/
    bash: cd: illegal option: -=
    cd: usage: cd [-PL] [dir]

    and if I add "\" to transfer the "-" symbol like:

    [[email protected] ]# cd \-\=New\ Game\=-/
    bash: cd: illegal option: -=
    cd: usage: cd [-PL] [dir]


    but I CAN use proftpd to enter this folder in remote ftp client, it is so
    odd!!!
    I am now confused with bash even I have played with it very well~~~
    what is wrong ??

    I use Redhat 7.2 and bash version is :

    [[email protected] ]# bash --version
    GNU bash, version 2.05.8(1)-release (i386-redhat-linux-gnu)
    Copyright 2000 Free Software Foundation, Inc.

    -K
     
    Ka, Aug 22, 2003
    #1
    1. Advertisements

  2. Ka

    Alan Connor Guest

    Why are you using a dirname like that?


    Try putting the name in quotes. It is the space as much as anything that is
    causing your problem. Then try changing the name with mv --....


    Alan C
     
    Alan Connor, Aug 22, 2003
    #2
    1. Advertisements

  3. Ka

    Ka Guest

    that is not my fault, but some ftp site's, so , ncftpget make the local
    dir name and then I want to cd it but failed. so I just want to know
    how to use command cd with some special writing ?

    how to cd a dir with name "-=" ??

    -K
     
    Ka, Aug 22, 2003
    #3
  4. Ka

    /dev/rob0 Guest

    [comp.unix.shell, which I do not read, added, followup-to set there]
    All that crossposting, yet you somehow missed comp.unix.shell. Why?

    Try this:
    http://www.google.com/search?as_q=bash+tutorial&as_oq=beginner+newbie+starting
    You didn't play as well as you thought. :)

    Despite being way off topic (in c.o.l.networking, where I read it) I'll
    give you your answer.
    [email protected]:~$ mkdir '\-=New Game=\-'
    [email protected]:~$ echo "$_"
    \-=New Game=\-
    [email protected]:~$ cd "$_"
    [email protected]:~/\-=New Game=\-$ cd
    [email protected]:~$ rmdir "$_"
    [email protected]:~$ echo 'good riddance to non-standard filename characters!'

    The problem is that the backslashes themselves either need another
    backslash (escape), or quoting. Notice the use of escapes and quoting
    above: single- and double-quotes act differently.
     
    /dev/rob0, Aug 22, 2003
    #4
  5. Ka

    Vilmos Soti Guest

    That's an impressive name!
    Bad start. You need to "disable", first of all, the leading hyphen since
    that is the thing which confuses everything. The easiest is to
    use the "./" construct.

    cd "./-=New Game=-"

    As a side note, I hope you don't ftp as root.
    The "=" is not an option for the cd command, and this confused
    cd.
    Escaping doesn't help here. This is why I wrote "disable" and not
    escape. The problem is that the first thing the "cd" command sees
    is a hyphen followed by an equal sign, and cd will interpret it
    as an (invalid) option. You need to make sure that cd doesn't see
    it as an option. By escaping it, you didn't accomplish anything since
    cd will still see the leading hyphen. Simply prepend a "./" to it
    and you are done.
    Since when you proftpd, it doesn't see it as an option. The option
    counts when you start the program and not afterwards with any input.

    If I start emacs with "emacs -blah", it might complain, but if once
    I started, I can enter "-blah" and it will not complain.
    Read the manpage for "rm" since that covers the "filenames with
    a leading hyphen" question.

    Vilmos

    PS. Please don't crosspost to so many newsgroups. I removed
    all of them except coln since my news server complained
    about them.
     
    Vilmos Soti, Aug 22, 2003
    #5
  6. Ka

    Guest Guest

    It is not a matter of bash. It is a matter of cd.

    You can escape characters the shell may use (e.g. "$"
    for a variable name if you want to include a "$").
    That gets past the shell. The "-" is used by cd.

    It is a buitin command but the "-" is passed along
    to it.

    So ... to make a directory with name "-me"

    The following depends on the shell (one can escape
    the "-" for the cd command built into tcsh, for example).

    Some commands have a way to tell them that *there are
    no more switches* - that is, every hyphen it sees from
    then on is plain text, not a marker for a switch.

    In the bash shell.

    mkdir -- -me

    creates the directory -me

    cd -- -me

    changes into that directory.

    cd ..

    moves back out of it.

    rmdir -- -me

    For these commands, a "--" switch indicates to
    the command that hyphens following it are text
    and not switch commands.

    (At one time I asked the support folks at my ISP
    why I could not delete a file that I got from
    uudecoding a usenet post with a hyphen at the
    beginning of the filename and they did not know how!
    At that time, being a newbie, I did not know what to
    do, so I ftp'ed to the site and then deleted it
    since ftp accepted the hyphen as text and not a
    switch.)
     
    Guest, Aug 22, 2003
    #6
  7. cd "-=New Game=-"

    or

    cd '-=New Game=-"

    I think both should work. But, the second one will definitely work.
     
    Davorin Vlahovic, Aug 22, 2003
    #7
  8. Ka

    Vilmos Soti Guest

    You must be kidding. Just see the second one's quotation marks. Both.

    Also, it wouldn't work since the quotation mark will not escape
    the leading hyphen. It will merely make sure that there is only
    one argument to cd, but it still won't work due to the leading
    hyphen. Read up on man rm to see how to get around this.

    Vilmos
     
    Vilmos Soti, Aug 22, 2003
    #8
  9. Ka

    Ka Guest

    YES, you are right!

    [[email protected]]# cd -- -\=New\ Game\=-/
    [[email protected] -=New Game=-]#
    yeah, :)) so did I~~, hehe. I rename it by proftpd~

    -K
     
    Ka, Aug 24, 2003
    #9
  10. Ka

    Guest Guest

    There you could have avoided the leaning toothpicks.

    The space is interpreted as a delimiter by the shell.
    The "=" may have a special meaning to the shell.

    cd -- '-=New Game=-'

    should work too (the problem is the hyphen at the
    start of the name which gets interpreted as a switch).
     
    Guest, Aug 24, 2003
    #10
  11. cd "./-=New Game=-"
     
    Chris F.A. Johnson, Sep 3, 2003
    #11
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.