Since you have a sed tag, here is the sed answer:
echo "$word" | sed -e "{ s/^\(.\).*/\1/ ; q }"
Play the game for those who like it (I do!):
{
s : run lookup/ : Start by indicating what needs to be replaced.^\(.\) : capture the first character in group 1.* :, make sure the rest of the line is in the wildcard/ : start specifying a replacement\1 : insert group 1/ : The rest is discarded ;
q : Close sed so that it does not repeat this block for other lines, if any.
}
Ok, that was fun! :) You can also use grep , etc., but if you are in bash , the magic of ${x:0:1} is still imo's best solution. (I spent an hour trying to use the POSIX variable extension, but could not :( )
phicr Mar 01 '17 at 18:00 2017-03-01 18:00
source share