The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
Korn: How to loop through a string character by character shew01 Shell Programming and Scripting 10 12-02-2008 07:58 AM
how to check string of character manas_ranjan Shell Programming and Scripting 9 05-12-2008 08:20 AM
Bash Script to check Remote Host Connection zulfikarmd UNIX for Dummies Questions & Answers 5 04-16-2008 07:53 AM
Special Character Check in Shell script mradul_kaushik Shell Programming and Scripting 1 03-24-2006 05:54 PM
Shell script: Cut / (slash) character in string ThuongTranVN UNIX for Dummies Questions & Answers 4 01-30-2001 12:35 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-18-2008
ole111 ole111 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1
bash script to check the first character in string

Hello
would appreciate if somebody can post a bash script that checks if the first character of the given string is equal to, say, "a"

thnx in advance
  #2 (permalink)  
Old 03-18-2008
jaduks's Avatar
jaduks jaduks is offline
Registered User
  
 

Join Date: Aug 2007
Location: Assam,India
Posts: 166
Code:
$ echo "unix" | awk 'BEGIN {FS=OFS=""} END { if (!found) print "FAILED" }
$1 == "u" { print "PASSED"; found++ }
'
PASSED

$ echo "unix" | awk 'BEGIN {FS=OFS=""} END { if (!found) print "FAILED" }
$1 == "g" { print "PASSED"; found++ }
'
FAILED
//Jadu
  #3 (permalink)  
Old 03-19-2008
faltooweb faltooweb is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 11
bash script to check the first character in string

This will work in bash/korn/baurne

str="$*"

case $str in
a*) echo "a found" ;;
*) echo " no a" ;;
esac
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0