Not sure why it is not working the following :
set -- $@
stype ="a"
for shell_args in "$@"
do
$stype=` awk '{print substr ("'"$shell_args"'", 0, 3)}' `
echo $stype
done
Thank you
Not sure why it is not working the following :
set -- $@
stype ="a"
for shell_args in "$@"
do
$stype=` awk '{print substr ("'"$shell_args"'", 0, 3)}' `
echo $stype
done
Thank you
Please put code inside
tags.
set -- $@
[/quote]
[indent]
Why?
Syntax error; there should be no space before = (and there's no need for the quotes).
stype=` awk '{print substr ("'"$shell_args"'", 0, 3)}' `
hi
Thanks for your help. I've made the modifications but still does not work:
code:
[#!/bin/sh
set -x
for shell_args in "$@"
do
stype=` awk '{print substr ("'"$shell_args"'", 0, 3)}' `
echo $stype
done
]
**************************
debug:
[sh mytest.sh es_GELitems1 ab_s1_Abools1 ai_s1_Aints1 as_s1_Astrings1 at_s1_Atests1 ee_ ei_s1_Eints
+ for shell_args in '"$@"'
++ awk '{print substr ("es_GELitems1", 0, 3)}'
]
stype=` awk 'BEGIN {print substr ("'"$shell_args"'", 0, 3)}' `
(It's very inefficient to call awk separately for every argument.)
for arg
do
stype=${arg%"${arg#???}"}
printf "%s\n" "$stype"
done
Thanks.
Wonderful solution!
Wow, I love it! Thanks cfa. All these years I've been doing:
for arg;do
stype=$(echo $arg|cut -b-3)
echo $stype
done