Question:
bash scripting problem :(?
Pardis
2012-12-12 10:31:49 UTC
I am very very new to bash scripting ...
I almost know nothing !
I have a problem that may seem really stupid ...

what is problem with this line?
read YEAR
AGE=$[ $2012 - $YEAR ]

after this line doesn't we have AGE with the value of 2012-YEAR?
tnx
Three answers:
Charlie Kelly
2012-12-12 19:10:00 UTC
read YEAR

echo $YEAR

let AGE=2012-$YEAR

echo "$AGE"



I don't think you want the $ in front of 2012, and I don't think you want to ever use $[], but i'm also learning. ${variableName[@]} this is perfectly acceptable though, the {} tell bash that it's definitely a variable, even if sometimes it's mashed up against something else. This is useful at times, or rather a good safe practice when running it up against something, like echo "word${YEAR}word"
jplatt39
2012-12-12 10:48:37 UTC
Why is there a dollar sign in front of 2012? Is that a variable name? I thought it was supposed to be a literal. If I do:



jplatt@darkstar ~ $ echo $[$2012-1955]



I get:

-1945



See my point? what is $[2012=-$YEAR]
anonymous
2016-12-08 17:31:26 UTC
i'm no longer that solid at shell scripting, yet for the 1st area i could propose making use of "ls" command insted of grep, some thing like this: #!/bin/sh if ls my.txt > /dev/null 2>&a million then echo "record chanced on" else echo "record no longer chanced on" fi study manuals for "I/O redirection in Linux", for the "> /dev/null 2>&a million area", this is used as a replace of -q for suppressing blunders outputs. Cheers!


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...