简体   繁体   中英

BASH: Is there any way to cut string returned by function using shell expansion tricks?

What i have:

MUSTBE_TIME=`GetPastHours $[$i-1]|cut -c 1-2`

It works. But is there away to do something like this ?

MUSTBE_TIME=${`GetPastHours $[$i-1]`:1:2}

Thanks,

(Incidentally, $[...] is an obsolete syntax; you should use $((...)) instead.)

bash doesn't allow nesting of parameter expansions, you can can't use the result of a command substitution as if it were a parameter. You can use a combination of the read command and process substitution, though.

read -n 2 MUSTBE_TIME < <(GetPastHours $((i-1)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM