Forgive me. I am very new to kornshell scripts. The simplest things stop me dead in my tracks.
Here are two such examples.
I want to save the first 19 characters of the following string to a variable.
"Operation Completed and blah blah blah"
I know this works (from another thread):
mystring="Operation Completed and blah blah blah"
echo $mystring | cut -c 1-19
But I cannot figure out how to save the output of the result of the cut command to a variable.
So because I could not do that, I tried to compare the result of the cut command to a variable containing "Operation Completed", only I can't get the comparison to work. I keep getting :Operation not found when I run the following shell.
cstring="Operation Completed"
mystring="Operation Completed and blah blah blah"
echo $mystring | cut -c 1-19
if [[ "$cstring" = $($mystring | cut -c 1-19) ]]; then
echo "they match"
fi
Thanks in advance.
some ways:
mystring="Operation Completed and blah blah blah"
echo $mystring | cut -c 1-19 | read myvariable
# or --------
myvariable=$(echo $mystring | cut -c 1-19 )
# or ---
myvariable=`echo $mystring | cut -c 1-19`
The ` bactick syntax is old but is allowed.
sb008
February 19, 2008, 2:01pm
3
nancylt723:
Forgive me. I am very new to kornshell scripts. The simplest things stop me dead in my tracks.
Here are two such examples.
I want to save the first 19 characters of the following string to a variable.
"Operation Completed and blah blah blah"
I know this works (from another thread):
mystring="Operation Completed and blah blah blah"
echo $mystring | cut -c 1-19
But I cannot figure out how to save the output of the result of the cut command to a variable.
So because I could not do that, I tried to compare the result of the cut command to a variable containing "Operation Completed", only I can't get the comparison to work. I keep getting :Operation not found when I run the following shell.
cstring="Operation Completed"
mystring="Operation Completed and blah blah blah"
echo $mystring | cut -c 1-19
if [[ "$cstring" = $($mystring | cut -c 1-19) ]]; then
echo "they match"
fi
Thanks in advance.
if [ "$cstring" = "$(echo $mystring | cut -c 1-19)" ]; then
echo "they match"
fi