![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Comparing filename-substrings and remove unnecessary files | cypher82 | UNIX for Dummies Questions & Answers | 5 | 06-06-2008 05:26 AM |
| comparing strings | agarwal | Shell Programming and Scripting | 3 | 04-16-2008 06:29 AM |
| Comparing Two Strings | Anji | Shell Programming and Scripting | 8 | 01-09-2008 06:32 AM |
| Comparing strings | yakyaj | UNIX for Advanced & Expert Users | 2 | 03-23-2007 01:22 AM |
| Breaking strings into Substrings | switch | Shell Programming and Scripting | 4 | 04-06-2006 05:29 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
ksh: Comparing strings that contain spaces and working with substrings
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:
Code:
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` |
|
||||
|
Quote:
Code:
if [ "$cstring" = "$(echo $mystring | cut -c 1-19)" ]; then echo "they match" fi |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|