[LUNA] simple(ton?) bash question ....
William A. Mahaffey III
wam at hiwaay.net
Fri Nov 21 14:49:10 CST 2014
On 11/21/14 14:31, Paul F. Pearson wrote:
>
> "William A. Mahaffey III" <wam at hiwaay.net> wrote:
>> Hmmmm .... I get:
>>
>> [root at Q6600:/etc, Tue Nov 18, 11:04 AM] 1085 # function lltr10 ()
>> {lltr
>> "$*" | tail -10}; export lltr10
>> -bash: syntax error near unexpected token `{lltr'
>> You have new mail in /var/spool/mail/root
>> [root at Q6600:/etc, Fri Nov 21, 11:11 AM] 1086 # which lltr
>> alias lltr='llt -r'
>> [root at Q6600:/etc, Fri Nov 21, 11:11 AM] 1087 # function lltr10 () {
>> lltr
>> "$*" | tail -10 }; export lltr10
>> > ^C
>> [root at Q6600:/etc, Fri Nov 21, 11:12 AM] 1088 # lltr10 () { lltr "$*" |
>>
>> tail -10 }; export lltr10
>> -bash: syntax error near unexpected token `('
>> [root at Q6600:/etc, Fri Nov 21, 11:13 AM] 1089 #
>>
>>
>> So the spaces around '{' & '}' are necessary (news to me), as
>> (apparently) is the function keyword .... Why does it go into a prompt
>>
>> when I define & export the function ? My ultimate goal is to put this
>>
>> stuff into a bashrc script, either per user or global, which is why I
>>
>> ask .... Thanks & TIA ....
>
> OK, here it is after I actually tried it (I don't have lltr as an alias, so I just used ls -ltr). This works with no reported errors.
>
> $ lltr10() { ls -ltr "$*" | head -10; }
> $ export lltr10
>
> The semicolon is special, as you're specifying a list of commands (technically, Compound Commands). See [1], [2], and [3].
>
> I *think* you're getting the '>' prompt and other errors because of the missing semicolon. I can't say for sure, because I don't know if you put it all on one line, or if email is word-wrapping for us. My examples are all on one line.
>
> [1] http://www.gnu.org/software/bash/manual/bashref.html#Lists
> [2] http://www.gnu.org/software/bash/manual/bashref.html#Shell-Functions
> [3] http://www.gnu.org/software/bash/manual/bashref.html#Compound-Commands
>
>
>
> ------
> Paul F. Pearson
> We all laugh in the same language
> _______________________________________________
> LUNA mailing list
> LUNA at lunagroup.us
> http://lunagroup.us/mailman/listinfo/luna
>
*Booooyah* !!!! I now have:
[root at Q6600:/etc, Fri Nov 21, 02:25 PM] 1099 # function lltr10 () { lltr
"$*" | tail -10; }; export lltr10
[root at Q6600:/etc, Fri Nov 21, 02:46 PM] 1100 # lltr10
ls: cannot access : No such file or directory
[root at Q6600:/etc, Fri Nov 21, 02:46 PM] 1101 # which lltr10
/usr/bin/which: no lltr10 in
(/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root at Q6600:/etc, Fri Nov 21, 02:46 PM] 1102 # lltr10 /etc/
30541490 4 -rw-r--r--. 1 root root 1138 May 3 2014
LIST.BurnDebian.AMD64-7.5.txt
30541495 4 -rw-r--r--. 1 root root 1146 May 3 2014
LIST.BurnDebian.kfreeBSD-7.5.txt
30541494 4 -rw-r--r--. 1 root root 1106 Jul 12 10:46
LIST.BurnUBCD-5.30.txt
30541497 4 -rw-r--r--. 1 root root 1148 Jul 12 10:53
LIST.BurnFreeBSD.10.0.txt
30541496 4 -rw-r--r--. 1 root root 1151 Jul 30 07:37
LIST.BurnFreeBSD.9.3.txt
30541499 4 -rw-r--r--. 1 root root 526 Sep 9 15:31 hosts
30541491 4 -rw-r--r--. 1 root root 1159 Sep 18 10:47
LIST.BurnCentOS.5.9.DVD.txt
30539814 4 drwxr-xr-x. 3 root root 4096 Nov 18 10:53 profile.d/
30541498 4 -rw-r--r--. 1 root root 369 Nov 21 11:16 mtab
30539777 12 drwxr-xr-x. 94 root root 12288 Nov 21 11:16 ./
[root at Q6600:/etc, Fri Nov 21, 02:46 PM] 1103 # which lltr
alias lltr='llt -r'
[root at Q6600:/etc, Fri Nov 21, 02:46 PM] 1104 #
& if you make the "$*" into "$@" it works w/ a NULL arg list (as per man
page, just checked) .... *hoooray* !!!! Thanks.
--
William A. Mahaffey III
----------------------------------------------------------------------
"The M1 Garand is without doubt the finest implement of war
ever devised by man."
-- Gen. George S. Patton Jr.
More information about the LUNA
mailing list