开发者

single quotes not working in shell script

I have a .bash_profile script and I can't get the following to work alias lsls='ls -l | sort -n +4'

wh开发者_开发百科en I type the alias lsls it does the sort but then posts this error message "-bash: +4: command not found" How do I get the alias to work with '+4'?

It works when type ls -l | sort -n +4 in the command line

I'm in OS X 10.4

Thanks for any help


bash-4.0$ ls -l | sort -n +4
sort: open failed: +4: No such file or directory

You need ls -l | sort -n -k 5, gnu sort is different from bsd sort

alias lsls='ls -l | sort -n -k 5'

Edit: updated to reflect change from 0 based indexing to 1 based indexing, thanks Matthew.


alias lsls='ls -l | sort -n +4' should work fine with the sort in OS X 10.4 (which does support that syntax).

when I type the alias lsls it does the sort but then posts this error message "-bash: +4: command not found"

Is it possible that you inserted a stray newline when editing your .bash_profile? e.g. if you ended up with something like this:

alias lsls='ls -l | sort -n
+4'

...that might explain the error message.


As an aside, you can get the same effect without piping through sort at all, using:

ls -lrS


This link discusses a very similar alias containing a pipe.

The problem may not have been the pipe, but the interesting solution was to use a function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜