Networking Forums

Networking Forums > Computer Networking > Linux Networking > confused with BASH shell in Redhat

Reply
Thread Tools Display Modes

confused with BASH shell in Redhat

 
 
Ka
Guest
Posts: n/a

 
      08-22-2003, 11:57 AM
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:

[root@mail ]# cd -\=New\ Game\=-/
bash: cd: illegal option: -=
cd: usage: cd [-PL] [dir]

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

[root@mail ]# 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 :

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

-K


 
Reply With Quote
 
 
 
 
Alan Connor
Guest
Posts: n/a

 
      08-22-2003, 01:04 PM
On Fri, 22 Aug 2003 19:57:13 +0800, Ka <(E-Mail Removed)> wrote:
>
>
> 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:
>
> [root@mail ]# cd -\=New\ Game\=-/
> bash: cd: illegal option: -=
> cd: usage: cd [-PL] [dir]
>
> and if I add "\" to transfer the "-" symbol like:
>
> [root@mail ]# 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 :
>
> [root@mail ]# bash --version
> GNU bash, version 2.05.8(1)-release (i386-redhat-linux-gnu)
> Copyright 2000 Free Software Foundation, Inc.
>
> -K
>
>


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




 
Reply With Quote
 
Ka
Guest
Posts: n/a

 
      08-22-2003, 01:18 PM

"Alan Connor" <(E-Mail Removed)> wrote in message
news:4xo1b.2881$(E-Mail Removed) nk.net...
> On Fri, 22 Aug 2003 19:57:13 +0800, Ka <(E-Mail Removed)> wrote:
> >
> >
> > 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:
> >
> > [root@mail ]# cd -\=New\ Game\=-/
> > bash: cd: illegal option: -=
> > cd: usage: cd [-PL] [dir]
> >
> > and if I add "\" to transfer the "-" symbol like:
> >
> > [root@mail ]# 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 :
> >
> > [root@mail ]# bash --version
> > GNU bash, version 2.05.8(1)-release (i386-redhat-linux-gnu)
> > Copyright 2000 Free Software Foundation, Inc.
> >
> > -K
> >
> >

>
> 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 --....
>


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

>
> Alan C
>
>
>
>




 
Reply With Quote
 
/dev/rob0
Guest
Posts: n/a

 
      08-22-2003, 01:33 PM
[comp.unix.shell, which I do not read, added, followup-to set there]
In article <bi50pu$1pm6$(E-Mail Removed)>, Ka wrote:
> I am confused with Bash, why ?


All that crossposting, yet you somehow missed comp.unix.shell. Why?

Try this:
http://www.google.com/search?as_q=ba...ewbie+starting

> I am now confused with bash even I have played with it very well~~~
> what is wrong ??


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.
rob0@obrien:~$ mkdir '\-=New Game=\-'
rob0@obrien:~$ echo "$_"
\-=New Game=\-
rob0@obrien:~$ cd "$_"
rob0@obrien:~/\-=New Game=\-$ cd
rob0@obrien:~$ rmdir "$_"
rob0@obrien:~$ 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 - preferred_email=i$((28*28+28))@softhome.net
or put "not-spam" or "/dev/rob0" in Subject header to reply
 
Reply With Quote
 
Vilmos Soti
Guest
Posts: n/a

 
      08-22-2003, 04:19 PM

"Ka" <(E-Mail Removed)> writes:

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


That's an impressive name!

> 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:
>
> [root@mail ]# cd -\=New\ Game\=-/


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.

> bash: cd: illegal option: -=
> cd: usage: cd [-PL] [dir]


The "=" is not an option for the cd command, and this confused
cd.

> and if I add "\" to transfer the "-" symbol like:
>
> [root@mail ]# cd \-\=New\ Game\=-/
> bash: cd: illegal option: -=
> cd: usage: cd [-PL] [dir]


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.

> but I CAN use proftpd to enter this folder in remote ftp client, it is so
> odd!!!


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.

> I am now confused with bash even I have played with it very well~~~
> what is wrong ??


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.
 
Reply With Quote
 
Spamless
Guest
Posts: n/a

 
      08-22-2003, 06:05 PM
In article <bi50pu$1pm6$(E-Mail Removed)>, Ka wrote:
> 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:
>
> [root@mail ]# cd -\=New\ Game\=-/
> bash: cd: illegal option: -=
> cd: usage: cd [-PL] [dir]


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.)
 
Reply With Quote
 
Davorin Vlahovic
Guest
Posts: n/a

 
      08-22-2003, 09:11 PM
In article <bi50pu$1pm6$(E-Mail Removed)>, Ka wrote:
> 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:
>
> [root@mail ]# cd -\=New\ Game\=-/
> bash: cd: illegal option: -=
> cd: usage: cd [-PL] [dir]
>
> and if I add "\" to transfer the "-" symbol like:
>
> [root@mail ]# cd \-\=New\ Game\=-/
> bash: cd: illegal option: -=
> cd: usage: cd [-PL] [dir]


cd "-=New Game=-"

or

cd '-=New Game=-"

I think both should work. But, the second one will definitely work.

--
Dammit, how many times do I have to tell you? FIRST you rape, THEN you
pillage!!
 
Reply With Quote
 
Vilmos Soti
Guest
Posts: n/a

 
      08-22-2003, 10:59 PM
Davorin Vlahovic <A-(E-Mail Removed)> writes:

> cd "-=New Game=-"
>
> or
>
> cd '-=New Game=-"
>
> I think both should work. But, the second one will definitely work.


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
 
Reply With Quote
 
Ka
Guest
Posts: n/a

 
      08-24-2003, 12:50 AM

"Spamless" <(E-Mail Removed)> wrote in message
news:3f465b57$(E-Mail Removed)...
> In article <bi50pu$1pm6$(E-Mail Removed)>, Ka wrote:
> > 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:
> >
> > [root@mail ]# cd -\=New\ Game\=-/
> > bash: cd: illegal option: -=
> > cd: usage: cd [-PL] [dir]

>
> 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


YES, you are right!

[root@mail]# cd -- -\=New\ Game\=-/
[root@mail -=New Game=-]#

>
> 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.)


yeah, :-)) so did I~~, hehe. I rename it by proftpd~

-K


 
Reply With Quote
 
Spamless
Guest
Posts: n/a

 
      08-24-2003, 09:40 AM
In article <bi9259$1bhq$(E-Mail Removed)>, Ka wrote:
>
> "Spamless" <(E-Mail Removed)> wrote in message
>> In the bash shell.
>>
>> mkdir -- -me
>>
>> creates the directory -me
>>
>> cd -- -me
>>
>> changes into that directory.
>>
>> cd ..
>>
>> moves back out of it.
>>
>> rmdir -- -me

>
> YES, you are right!
>
> [root@mail]# cd -- -\=New\ Game\=-/
> [root@mail -=New Game=-]#


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).
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy files using filenames from text files with shell script or bash script altariamx2003@gmail.com Linux Networking 4 11-23-2006 08:27 AM
Linux bash syntax Q: Coenraad Loubser Linux Networking 4 01-16-2005 05:31 PM
zmienna bash Zenon Linux Networking 1 05-07-2004 11:21 AM
Setting $TERM when using rsh and ssh with bash waterbottleboodle Linux Networking 1 11-08-2003 10:29 PM
Bash script via inetd = no joy tylernt Linux Networking 10 09-05-2003 08:53 PM



1 2 3 4 5 6 7 8 9 10 11