views:

60

answers:

2
market_l="${echo $1 | awk '{print tolower($0)}'}"
echo $market_l

when i execute this its giving me an error below:

./test: market_l="${echo $1 | awk '{print tolower($0)}'}": The specified substitution is not valid for this command.
+1  A: 

Did you mean to use the $() operator instead of ${}?

Marcelo Cantos
i want to convert the $1 argument supplied while executing the script to lowercase and store it in a variable and then echoing it.
Vijay Sarathi
I Think you are right.thanks for the hint.
Vijay Sarathi
+1  A: 

you should use $() to assign output to a variable. not ${}

market_l="$(echo $1 | awk '{print tolower($0)}')"

or you can do it with ksh

#!/bin/ksh
typeset -l market_l
market_l="$1"
echo $market_l

Other ways to change case besides awk, fyi

$ echo "$1"|tr [A-Z] [a-z]

$ echo "$1"|sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'
ghostdog74
don't forget to use quotes: `"$1"`. Always quote unless you specifically don't want to.
glenn jackman
actually in the example, its alright not to use quotes since the output of echo is the same. but yes, you are right to always use quotes where necessary.
ghostdog74