Finding 'ls' to bypass system alias


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding 'ls' to bypass system alias
# 1  
Old 04-27-2015
Finding 'ls' to bypass system alias

Heyas

Just asking, is there a better to make sure the script will use the binary and not some alias?

Code:
LS=$(locate "ls"|grep /bin/ls$ | head -n 1)

Thank you.
# 2  
Old 04-27-2015
'locate' is not a good idea. It's not installed on many systems, and may be unused on some where it is.

Insisting on /bin/ls is not a good idea. Some distributions might insist on putting them somewhere else.

Aliases are an interactive session thing -- they're not generally enabled in scripts at all. You have to go to special effort to make them happen. So this is probably unnecessary.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 04-27-2015
Code:
LS='\ls'

Or simply define:LS='/bin/ls' and use $LS in your script - that's what I usually do for most/all the tools.

Last edited by vgersh99; 04-27-2015 at 07:19 PM..
This User Gave Thanks to vgersh99 For This Post:
# 4  
Old 04-27-2015
Could you please be a litte bit more elaborate regarding that 'somewher else'?

Figured, if one exports an alias (named 'ls'), it interferes with the use of 'ls' inside a script.
Saying:
In the script i wanted to use ls -l to get a file its bytesize, but the followed math failed as it used the alias, which already was ls -lh.

Thank you

EDIT:
vgersh99, ty i'll try that.
# 5  
Old 04-27-2015
Code:
\ls ...

That will bypass any alias for "ls" and use whatever binary it finds in your PATH envval, assuming you're running bash.
This User Gave Thanks to achenle For This Post:
# 6  
Old 04-28-2015
Quote:
Originally Posted by achenle
Code:
\ls ...

That will bypass any alias for "ls" and use whatever binary it finds in your PATH envval, assuming you're running bash.
That isn't just bash. Any POSIX conforming shell will ignore any defined aliases if one or more characters of the command's name are quoted. So, any of the following will work:
Code:
"ls" 
\ls
l\s
l's'

These 3 Users Gave Thanks to Don Cragun For This Post:
# 7  
Old 04-30-2015
Quote:
Originally Posted by sea
Figured, if one exports an alias (named 'ls'), it interferes with the use of 'ls' inside a script.
When you run a shell script, it shouldn't get your aliases. They're not inherited the way environment variables and the like are.

Shell scripts don't usually process aliases unless they're interactive, either.

How exactly are you running your shell script, for these aliases to get processed? I suppose it'd have your aliases if you were sourcing it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding all files w/ suffix on the system

I am trying to build a list of all files ending in *.cbl in the system, but when I try find / -name *.cbl, I only find one specific file name that is alphabetically first. Is there something I'm missing? TIA ---------- Post updated at 11:20 AM ---------- Previous update was at 11:15 AM... (1 Reply)
Discussion started by: wbport
1 Replies

2. Solaris

Finding system uptime without login

Hi, Am writing a script where I want to find uptime of certain servers. Is there any command where we can find uptime without login to the server, since the server list is big logging to the server will time consuming. Thanks in advance (7 Replies)
Discussion started by: rogerben
7 Replies

3. Shell Programming and Scripting

finding the hostname of a remote system

I know the ipaddress of a remote machine and would like to know its hostname I used the nslookup command but... is there an easier way of doing it... just like hostname command. When i give this command i get the following nslookup 10.2.47.36 Server: 10.233.04.31 Address: ... (2 Replies)
Discussion started by: ramky79
2 Replies

4. Solaris

root password for system maintenance (control-d to bypass)

I have message "root password for system maintenance (control-d to bypass)" after Solaris 10 boots up. Why it appears ? thx for help. (3 Replies)
Discussion started by: presul
3 Replies

5. Shell Programming and Scripting

Kornshell finding operating system

This should be really simple but I can't figure it out. :wall: Whats the command to find the operating system version thats running. I need to know if the node my script gets run on is HP-UX or linux or AIX or Oracle (6 Replies)
Discussion started by: Blogger11
6 Replies

6. Solaris

Finding most busy file system

Hi Experts, I was asked to find most busy file system on one of the server. It is Sun 10. Any idea to get this? Thanks, Deepak (5 Replies)
Discussion started by: naw_deepak
5 Replies

7. UNIX for Dummies Questions & Answers

Finding out which file system a machine has

Hi, when I run sfdisk -l get: Disk /dev/sda: 19452 cylinders, 255 heads, 63 sectors/track Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0 Device Boot Start End #cyls #blocks Id System /dev/sda1 * 0+ 12 13- 104391 83 Linux... (1 Reply)
Discussion started by: mojoman
1 Replies

8. UNIX for Dummies Questions & Answers

Finding unix file system

Hi, I have here a hard drive from a computer that was damaged, and now the costumer needs the data on the hard drive, but doesn't have any other computer to read data. I don't really know what file system is on the disk. How can I find out what file system is on the disk so I can read the... (4 Replies)
Discussion started by: dmarques
4 Replies

9. UNIX for Dummies Questions & Answers

Finding system info

Can someone tell me the command to display the info about the CPU? I need the CPI id.. of my SUN box. Solaris 8. It's some totally un-intuitive command, and i can't recall it. tnx. (3 Replies)
Discussion started by: ireeneek
3 Replies

10. UNIX for Dummies Questions & Answers

Finding out available C++ compilers on my system

How can I find out what C++ compilers are available on my system? Thanks in advance (7 Replies)
Discussion started by: HelpMeIAmLost
7 Replies
Login or Register to Ask a Question