bash env vars alias's & .bashrc
Hello all
I'm just trying to do a simple task. I'm making an alias to take a screenshot or screen grab. I don't know why it does not work; In my .bashrc file I have: if [ -x /usr/bin/import ] ; then export MYTIME=`/bin/date +%r | /usr/bin/awk '{print $1}'`; alias grab="/usr/bin/import -window root screenShot-$MYTIME.jpg"; fi OK, so the test works, I have import (image magick) - line 1 But $MYTIME gets the value of the time of the instance of the shell being created and not the time at whch I execute the alias! So I get: micxz@mars:~> echo $MYTIME 04:29:08 micxz@mars:~> echo $MYTIME 04:29:08 At any time! So my screen shot file gets overwritten each time because the time var does not change. I get, "screenShot-04:29:08.jpg" every time; How would I get the value of $MYTIME to be current when I execute "grab"? Or is there a better way? And how do ", ', and ` differ in shell interpretation? Thanks in advance; |
Other implementation with different quotation
Code:
function mytime { /bin/date +%r | /usr/bin/awk '{print $1}'; } |
if [ -x /usr/bin/import ] ; then
function mytime { /bin/date +%r | /usr/bin/awk '{print $1}' } alias grab="/usr/bin/import -window root screenShot-'mytime'.jpg"; fi I get Now: bash: /home/micxz/.bashrc: line 53: syntax error near unexpected token `fi' bash: /home/micxz/.bashrc: line 53: `fi' |
You have wrong type of parenthesis.
|
Syill get:
bash: /home/micxz/.bashrc: line 52: syntax error near unexpected token `fi' bash: /home/micxz/.bashrc: line 52: `fi' With $() style, Backwuotes are checked. I have: if [ -x /usr/bin/import ] ; then function mytime { /bin/date +%r | /usr/bin/awk '{print $1}' }; alias grab="/usr/bin/import -window root screenShot-$(mytime).jpg"; fi |
You know what forget this bashrc stuff. I'm just going to write a small bash script that does this and put it in my bin dir. Thanks for your help anyhow;
|
I doubt you can define a function inside of an if statement. What you can definitely do is create a function, and then subjectively call it from inside the if statement, like so:
function blah() { ... } if (something) { blah(); } Ignore the formatting, that's C type formatting, but you get the idea I hope. Edit: those brackets for your if condition look suspicious, try round brackets, also I highly doubt that semicolon should be there after the condition and before the then. |
Quote:
Just read what i said -- also the two first points -- or copypaste this: Code:
if [ -x /usr/bin/import ] ; then Sorry for getting nerwous, but I do am repeating myself. ;) |
Thanks ToniT
Your right I did not read it closly enough' I see now the ";"'s are not needed. I decided to build a small useless program for practice that does a bit more. I posted it here:
http://www.linuxquestions.org/questi...hreadid=101534 You were right! Thanks again! |
All times are GMT -5. The time now is 02:05 PM. |