Hello!
Please bare with me, I'm a total newbie to scripting. Here's the sudo code of what I'm trying to do:
Get file name
Does file exist?
If true
get length of file name
get network id (this will be the last 3 numbers of the file name)
loop x 2
If first character of if :=0
delete first character
else
exit loop
fi
end loop
Currently I have:
[-f /var/named/$Server ] && flag="true" || flag="false"
if $flag
then
echo "yey"
length=$((${#s}-2))
ipmid='expr substr $s $((length)) 3'
if [ ${ipmid:0:1} = 0 ]
then
????
fi
else
echo "Something went wrong! Whoops!"
fi
exit 0
with the s variable being the user input which looks like "test001" or "testtwo010"
As you can see I'm having trouble with the sed that will chop of the first character.
I tried :
echo $ipmid | cut -c2-
but that will print the last 2 characters but not chop off the first.
Ive also tried hacking as sed with
$ipmid | sed 's/.\(.*\)/\1/'
but that just gets me an error :o
Thanks!
Katie
---------- Post updated at 10:59 AM ---------- Previous update was at 10:16 AM ----------
fixed it, Thanks, and sorry for clogging up your threads!
If anyone is interested the solution is:
ipmid=${ipmid#?}