Bash alias for complicated ls command does not work.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash alias for complicated ls command does not work.
# 8  
Old 03-16-2010
ok function it is. Smilie

Thanks radoulov. Your function works perfectly.

However one thing I didn't mention before is that I was doing a second ls alias called lfq which added the ls switch -Q to wrap "" around the filenames so that files with spaces would be conveniently enclosed in "".

My attempts to modify your function to achieve this have failed dismally. Can it be done, if so, how?

Thanks again.
# 9  
Old 03-16-2010
Code:
lfq() {
  perl -le'
    -f and print qq("$_") for glob "*"
    '
    }

# 10  
Old 03-16-2010
To do this with unix "find" we'll need to know which Operating System you have.
# 11  
Old 03-16-2010
Shell only:

Code:
lfq() {
  for f in *; do
    [ -f "$f" ] && 
      printf '"%s"\n' "$f"
  done
  }


Code:
lf() {
  for f in *; do
    [ -f "$f" ] && 
	  printf '%s\n' "$f"
  done
  }



---------- Post updated at 07:20 PM ---------- Previous update was at 07:11 PM ----------

Actually, I would recommend the shell only solution.
# 12  
Old 03-16-2010
Quote:
Originally Posted by radoulov
Code:
lfq() {
  perl -le'
    -f and print qq("$_") for glob "*"
    '
    }

Thanks again radoulov, works a treat. Appreciate your time. Smilie

methyl - no need radoulov's function solution is perfect and done. Thanks anyway.

---------- Post updated at 06:28 PM ---------- Previous update was at 06:20 PM ----------

Quote:
Originally Posted by radoulov
Shell only:

Code:
lfq() {
  for f in *; do
    [ -f "$f" ] && 
      printf '"%s"\n' "$f"
  done
  }

Code:
lf() {
  for f in *; do
    [ -f "$f" ] && 
      printf '%s\n' "$f"
  done
  }



---------- Post updated at 07:20 PM ---------- Previous update was at 07:11 PM ----------

Actually, I would recommend the shell only solution.
Ok, I've tested those and they work perfectly as well.

Any particualar reason why they are preferable?

Cheers.
# 13  
Old 03-16-2010
Quote:
Originally Posted by gencon
[...]


Ok, I've tested those and they work perfectly as well.

Any particualar reason why they are preferable?
They are faster ...
# 14  
Old 03-16-2010
Quote:
Originally Posted by radoulov
They are faster ...
Ok, done. That's a good enough reason for me! Smilie

Thanks again for all your help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Alias does not work with bash profile

Hi, Below is what i have in my profile: alias wldm='cd /opt/app/wls' If i use bash or ksh shell this alias does not work. What should be done for this alias to work with all these simultaneously -> No Shell, bash shell, and ksh shell (14 Replies)
Discussion started by: mohtashims
14 Replies

2. UNIX for Dummies Questions & Answers

Using alias to create subshell and work in it

using kerberos to access remote server. first I execute kshell to create subshell and then kinit username@domain in that subshell. After that it prompts to enter password. Since I need to do this over and over, I am trying creating alias. I tried kshell; kinit username@domain. Did not work,... (7 Replies)
Discussion started by: analyst
7 Replies

3. Shell Programming and Scripting

complicated exclude option in find command

Hi all, In a directory, I have many video files. Example : As you can see, some of the video files come with a .aspx file (wich means the video is actually being uploaded and not entirely written on the FS) I try to write a bash script that would find all video files in the ... (1 Reply)
Discussion started by: gniagnia
1 Replies

4. UNIX for Dummies Questions & Answers

A very simple script, but alias won't work

I am new to unix and therefore I did a lot of reading before posting. So please, if this has been answered before, forgive me for re-posting and point me to the right place for the answer. I have spent many hours searching the net and read over 50 posts in this forum and even tried a few thing but... (20 Replies)
Discussion started by: sssccc
20 Replies

5. Shell Programming and Scripting

complicated alias command

hi guys i m making one alias which will set variable , invoke sqlplus and also set prompt of sqlplus,,i have made successfully upto invoking sqlplus in unix but cant pass command in sqlplus here is the command alias sett='export ORACLE_SID=devdb2;sqlplus system/system@test' now this... (3 Replies)
Discussion started by: tapia
3 Replies

6. Linux

Complicated Join command!

Hi I have a serious issue when trying to join to files so I have two files, one for meals and one for people Meal1:Turkey:Potato Chips:Twinkie:Coke:5.95 Meal2:Ham & Cheese:Doritos:Cookie:Sprite:6.49 Meal3:Vegetarian:Cheese Crackers:Brownie:Pepsi:5.75 Meal4:Tuna:Cheese Puffs:Eclair:Diet... (1 Reply)
Discussion started by: ehshi1992
1 Replies

7. Shell Programming and Scripting

Global alias does not work in shell script

Hi Linux Set up - alias ls='ls -l' Then run script #! /bin/ksh sub() { ls } sub Is there any way to get it working. I don't want to define alias inside of the program Thank you (2 Replies)
Discussion started by: zam
2 Replies

8. UNIX for Dummies Questions & Answers

Alias, function or script (bash) to "revert" cd command?

In all of my brief and superficial experience with Unix or Linux, the one curious and consistent thing has been that 'cd ./' (back up one directory level) has done absolutely nothing in any of them. Now I understand that, at least for bash, 'cd ./' appears to have been substituted by 'cd ..' Am... (1 Reply)
Discussion started by: SilversleevesX
1 Replies

9. Shell Programming and Scripting

alias doesn't work

Hi I have put alias ll='ls -la' in .profile file but it doesn't work. On hand it works it looks like the .profile file is not beeing read. How to check whitch file is loaded? ,profile? .bash_profile? My system: SunOS mion 5.10 Generic Shell: /bin/pfksh Thanks (2 Replies)
Discussion started by: miojamo
2 Replies

10. UNIX for Dummies Questions & Answers

more command does not work in bash shell

is there a different command to display contents of a file on the output in bash shell? i tried more and it does not work. (7 Replies)
Discussion started by: npatwardhan
7 Replies
Login or Register to Ask a Question