[LUNA] simple(ton?) bash question ....

William A. Mahaffey III wam at hiwaay.net
Fri Nov 21 11:18:03 CST 2014


On 11/21/14 10:49, Paul F. Pearson wrote:
> (1) Consider some of the bash and bourne shell tutorials.
>
> (2) when declaring functions in bash/sh, you use empty parens. Also, the keyword 'function' is a bash-ism -- not wrong, but IMO it doesn't add much.
>
> (3) You likely should consider using quotes as a habit, to help avoid corner cases (sadly, some file names contain whitespace).
>
> Here's my take on what you're trying to acheive (hasn't been tested, so beware...).
>
> $ lltr10 () { lltr "$*" | tail -10 }
> $ export lltr10
>
> or
>
> $ function lltr10 () { lltr "$*" | tail -10 }
> $ export lltr10
>
>
>
> ------
> Paul F. Pearson
> We all laugh in the same language
>
> ----- "William A. Mahaffey III" <wam at hiwaay.net> wrote:
>
>> .... I am trying to setup some aliases under bash. Since bash
>> apparently
>> can't use positional parameters in aliases, I am then trying a
>> function:
>>
>>
>> [root at Q6600:/etc, Tue Nov 18, 10:54 AM] 1075 # function lltr10 (lltr
>> $*
>> | tail -10); export lltr10
>> -bash: syntax error near unexpected token `ls'
>> [root at Q6600:/etc, Tue Nov 18, 10:54 AM] 1076 # function lltr10 (lltr
>> "$*" | tail -10); export lltr10
>> -bash: syntax error near unexpected token `ls'
>> [root at Q6600:/etc, Tue Nov 18, 10:55 AM] 1077 # function lltr10 (lltr
>> "$@" | tail -10); export lltr10
>> -bash: syntax error near unexpected token `ls'
>> [root at Q6600:/etc, Tue Nov 18, 10:55 AM] 1078 # function lltr10 (lltr
>> $@
>> | tail -10); export lltr10
>> -bash: syntax error near unexpected token `ls'
>> [root at Q6600:/etc, Tue Nov 18, 10:55 AM] 1079 # which lltr
>> alias lltr='llt -r'
>> [root at Q6600:/etc, Tue Nov 18, 11:00 AM] 1080 # which llt
>> alias llt='ll -t'
>> [root at Q6600:/etc, Tue Nov 18, 11:00 AM] 1081 # which ll
>> alias ll='la -lis'
>> [root at Q6600:/etc, Tue Nov 18, 11:00 AM] 1082 # which la
>> alias la='lf -a'
>> [root at Q6600:/etc, Tue Nov 18, 11:00 AM] 1083 # which lf
>> alias lf='ls -F'
>>           /bin/ls
>> [root at Q6600:/etc, Tue Nov 18, 11:00 AM] 1084 #
>>
>> What am I doing wrong here :-/ ? TIA for any & all clues ....
>>
>>
>> -- 
>>
>> 	William A. Mahaffey III
>>
>>   
>> ----------------------------------------------------------------------
>>
>> 	"The M1 Garand is without doubt the finest implement of war
>> 	 ever devised by man."
>>                              -- Gen. George S. Patton Jr.
>>
>> _______________________________________________
>> LUNA mailing list
>> LUNA at lunagroup.us
>> http://lunagroup.us/mailman/listinfo/luna
> _______________________________________________
> LUNA mailing list
> LUNA at lunagroup.us
> http://lunagroup.us/mailman/listinfo/luna
>

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 ....

-- 

	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