Our new Indie Games subforum is now open for business in G&T. Go and check it out, you might land a code for a free game. If you're developing an indie game and want to post about it, follow these directions. If you don't, he'll break your legs! Hahaha! Seriously though.
Our rules have been updated and given their own forum. Go and look at them! They are nice, and there may be new ones that you didn't know about! Hooray for rules! Hooray for The System! Hooray for Conforming!
I'm trying to pare down a string from something like this:
Database name : mysite_drupal
to just plain
mysite_drupal
What I have so far:
sitename=$(drush status | grep "Database name")
sitename=${sitename##*:} //this is supposed to get rid of all characters until the last instance of :
echo xxx $sitename xxx
The xxx strings are there so I can see what's being output where, and here's the kicker, the output looks like this:
xxxmysite_drupal
It is ignoring the first space and completely truncating the xxx after the sitename, and I don't know why.
I'm trying to pare down a string from something like this:
Database name : mysite_drupal
to just plain
mysite_drupal
What I have so far:
sitename=$(drush status | grep "Database name")
sitename=${sitename##*:} //this is supposed to get rid of all characters until the last instance of :
echo xxx $sitename xxx
The xxx strings are there so I can see what's being output where, and here's the kicker, the output looks like this:
xxxmysite_drupal
It is ignoring the first space and completely truncating the xxx after the sitename, and I don't know why.
Does that grep return that string like you typed?
I tried it and it works for me if I just use a string as initial sitename. Only thing I can think of is that grep isn't returning what you are expecting.
Use awk. You can have it split on spaces and then print the last field (assuming that "Database name : mysite_drupal" is the whole string).
eg: echo $var | awk F ' ' '{print $NF }'
(i'm not sure on the syntax, but you can google 'awk print last field')
edit: I'm not sure if this is bash or what, but awk is a linux command so if you have some way to run it from within the language you're using it should still be fine.
Posts
Does that grep return that string like you typed?
I tried it and it works for me if I just use a string as initial sitename. Only thing I can think of is that grep isn't returning what you are expecting.
Edit: Hmm.
tar -czf $sitename.tar.gz .
gives me this:
tar: \r.tar.gz: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors
and ends up creating sitename_drupal just fine, minus the .tar.gz. Maybe I can hack it by renaming the file afterwards.
eg: echo $var | awk F ' ' '{print $NF }'
(i'm not sure on the syntax, but you can google 'awk print last field')
edit: I'm not sure if this is bash or what, but awk is a linux command so if you have some way to run it from within the language you're using it should still be fine.
In a script obviously, I can't just do "mv myfile.tar.gz myfile_08_18_10.tar.gz" of course.
edit: disregard, I found the answer.