[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Tackling parameter expansion in functions
From: |
Greg Wooledge |
Subject: |
Re: [Help-bash] Tackling parameter expansion in functions |
Date: |
Fri, 12 Feb 2016 08:09:33 -0500 |
User-agent: |
Mutt/1.4.2.3i |
On Fri, Feb 12, 2016 at 12:56:22PM +0100, Richard Taubo wrote:
> # ----------------- This Works
> ----------------------------------------------------
>
> Test() {
> printf "my_word" | head -c${1:-7}
> }
>
> Test
Since there is no argument in this case, ${1:-7} expands to 7.
So you are runing ... | head -c7
> # ----------------- Does not work ---------------------------------------
> Test2() {
> printf "$1" | head -c${1:-7}
> }
> Test2 "my_word"
There is an argument in this case, so ${1:-7} expands to my_word.
So you are running ... | head -cmy_word
It seems unlikely that you wanted to use $1 in both places inside
the function. Did you really mean to use $1 on the left and $2 on
the right, perhaps? (But neither of your examples showed two
parameters.)
What are you actually trying to do?