bash - How to get first character of variable -
i'm trying first character of variable, i'm getting bad substitution error. can me fix it?
code is:
while ifs=$'\n' read line if [ ! ${line:0:1} == "#"] # error on line eval echo "$line" eval createsymlink $line fi done < /some/file.txt am doing wrong or there better way of doing this?
-- edit --
as requested - here's sample input stored in /some/file.txt
$moz_home/mobile/android/chrome/content/browser.js $moz_home/mobile/android/locales/en-us/chrome/browser.properties $moz_home/mobile/android/components/contentpermissionprompt.js
to first character of variable need say:
v="hello" $ echo "${v:0:1}" h however, code has syntax error:
[ ! ${line:0:1} == "#"] # ^-- missing space so can trick:
$ a="123456" $ [ ! "${a:0:1}" == "#" ] && echo "doesnt start #" doesnt start # $ a="#123456" $ [ ! "${a:0:1}" == "#" ] && echo "doesnt start #" $ also can done this:
$ a="#123456" $ [ "$(expr substr $a 1 1)" != "#" ] && echo "does not start #" $ $ a="123456" $ [ "$(expr substr $a 1 1)" != "#" ] && echo "does not start #" not start # update
based on update, works me:
while ifs=$'\n' read line echo $line if [ ! "${line:0:1}" == "#" ] # error on line eval echo "$line" eval createsymlink $line fi done < file
Comments
Post a Comment