(probably stupidly simple) if [ $var1 = $var2 ] problem...
OK, while I'm not new to the Mac or some of the the inner workings of Mac OS X I am quite new to scripting. And while I have "Learning the Bash Shell" by those lovely people at O'Reilly (Cameron Newham et. al.) I'm missing something, I just know I am.
Here's the problem:
At the beginning of my script I declare 2 variables:
Then, later I want to log which type of timestamp is being used, so I tried every variation I could think of on:
My problem occurs at the [ $timestamp=date ] and [ $timestamp=date -u ] bits. It fails numerous ways and the best I've got is where it logs both "Logging using Server's Local Time" AND "Logging using UTC".
I've tried various combinations of:
etc...
I also tried this
(and one for date -u)
and then using them like:
etc.
Still no joy
... I could go on. But at 03:00 this morning I decided to go to bed and ask. So here I am, asking.
Is it clear what I'm trying to do? Test which version of $timestamp the script is using an log the fact (even though it'll be obvious from the timestamps themselves which version is being used. It's more an exercise in what's possible and to learn how to do it than to do any rocket science).
Use quotes + date has to execute as a child process in order top return a value.
I'm sure I tried those variations last night. I'll have another go as to be honest my brain was getting a bit wooly around the edges by the end of it all and I might just be randomly lying!
Anyway, thank you. I appreciate the swiftness of response!
Hello,
In one part of my shell program I need to translate many of lines in the following pattern :
/(folder1|...|folderN)/(sub1|...|subN)/.../(file1|...|fileN)
into strings :
/folder1/sub1/.../file1
/folder1/sub1/.../...
/folder1/sub1/.../fileN
...
/folderN/subN/.../fileN
the... (2 Replies)
Hi there, Im sure there is a simple explanation for this but I have a file like this with no balnk lines
peter
paul
john
I run the command
# var=`grep paul file.txt`
# echo $var
paul
# echo $var | wc -l
1
but when I grep for a value that isnt in the file, i still... (4 Replies)
Hi, I have a very simple script like below:
for n in 10 20 30
do
for a in 30 40 50 60 70 80
do
for r in 2 3 4 5 6 7
do
m=$((r*a))
count=1
while
do
echo "a = " $a ", m = " $m ", n = " $n
... (2 Replies)
HI
i like to concatenate the two variables
var1=$line (ie 22885068900000652 B86860003OLFXXX592123320081227)
var2=$amount (ie 123456)
i want to club together both the above varaible var1 & var2 and assign back to var1
right now i am doing like this but it is not working.
var1=`echo... (1 Reply)
Googling the answer to this question just doesn't work when Google won't search your symbols for you. Can someone tell me what this command will assign to var2, and where I can find more information about using braces in this way?
var2=${var1#??????????}
Thanks so much. (2 Replies)
Hey guys,
I've bought a second-hand RS/6000 hardware with freshly installed AIX 5.3 on disk2 and freshly installed AIX 6 on disk1. I'm in possession of the original 5.3 install cds but the AIX 6 installation is just on the disk, I've no install media.
So first after getting the system, I... (3 Replies)
Hi there,
I was trying to add a line of text in the middle line of a file.
I have counted the lines in the file, and then I divide it into 2, after that I am stuck on how am I suppose to append the line on that file? When I tried to use this command 'second line >> filename' it appends it at... (3 Replies)
Hello,
I have created numerous variables called $mask1 $mask2... $maskN. I wish to echo these variables, below is the code for the two functions, the first creates the variables and the second echos them.
It is the second function which does not work. The line (i believe to be wrong) is in... (1 Reply)
I'am doing a tutorial where a simple calculator was given, then i noticed that you can't actually multiply
this is how i have approached the problem so far. i just need if the user enters "*"
to change it to "/*" ,is it possible? i know that * means the name of the last file in the directory... (8 Replies)
*EDIT -- **FIXEd I must've done something wrong, because it works now..
I punched in "if" in the forum search but nothing came up, so I'm posting it here.
Quick question: Can someone correct my syntax.
#!/bin/ksh
if (( var >= 1 && var <= 5 )); then
.................................. (1 Reply)