The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - Newcomers (http://hintsforums.macworld.com/forumdisplay.php?f=15)
-   -   Dumping file names with ls (http://hintsforums.macworld.com/showthread.php?t=98153)

sox 01-27-2009 02:03 PM

Do this
 
here is the solution I use.

instead of

ls *.txt

add a slash:

\ls *.txt

it appears that ls is alaised somehow to run through a formatter. Using the slash causes it to use the unaliased generic ls.

hayne 01-27-2009 02:23 PM

Quote:

Originally Posted by sox (Post 515765)
it appears that ls is aliased somehow to run through a formatter

The "somehow" must be something that you configured (in the shell "dot" files - see the shell config section of this Unix FAQ)
or something that you installed.

Hal Itosis 01-27-2009 05:37 PM

Quote:

Originally Posted by sox (Post 515765)
Using the slash causes it to use the unaliased generic ls.

That's pretty neat (and news to me anyway).
I knew about the "command" command (for bypassing shell builtins and/or user-defined functions in scripts).

But why does the \backslash work?
Doesn't appear to be a keyword...
$ type \
>
[^C]
$ type \\
-bash: type: \: not found

$ type '\'
-bash: type: \: not found

--

Hmm, apparently the \ has the same effect as *quoting* the text.
So, typing...
'ls'
would have the same effect: bypass the alias and run the standard utility.

Still not clear why that works tho.

hayne 01-27-2009 06:39 PM

The page http://www.chiark.greenend.org.uk/~s...m/aliases.html (about special uses of aliases) explains:
Quote:

Originally Posted by above web page
It's worth bearing in mind that you can bypass any alias definition by prefixing it with a backslash: instead of starting your command with ‘find’, use ‘\find’. This works because alias lookup happens before backslash escapes are processed, so the shell actually looks for an alias called ‘\find’, which doesn't exist.


Hal Itosis 01-27-2009 07:12 PM

Interesting page!

I can relate to his "find" example there.
For a few scripts, i've even used this heading:
#!/bin/bash -f -

to kill globbing within the whole script... so that stuff like "*.txt" can be
passed to internal functions without expanding (if something in the cwd
happened to match).


All times are GMT -5. The time now is 10:17 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.