| Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free! |
Check if variable starts with /
|
Original Message
|
Name: Jens Nielsen
Date: April 26, 2004 at 13:23:38 Pacific
Subject: Check if variable starts with / OS: HP Unix CPU/Ram: ?
|
Comment: Hello, I'm trying find a way to check if a variable starts with forward slash "/". Whoever, nothing that I have tried seems to work. For example, I want to perform the following check on my "out_dir" variable. But it fails the check if [ $out_dir != /* ] then echo Error! - Invalid directory specified echo Script will exit - please run it again exit fi Any assistance would be great. Jens
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: Wolfbone
Date: April 26, 2004 at 14:49:02 Pacific
|
Reply: (edit)if [ $(echo $out_dir | sed 's%^/%%') = $outdir ] then .... .... If your shell is bash (maybe also ksh?): if [[ ${out_dir:0:1} != "/" ]] then .... ....
Report Offensive Follow Up For Removal
|

Post Locked
This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
Go to Unix Forum Home