expr to translate the date command

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions expr to translate the date command
# 8  
Old 03-02-2011
Quote:
Originally Posted by linuxtraining
Yes. I even made sure by doing echo $SHELL and it printed bash.
That's your login shell, not what you're using in your shell script.

I see #!/bin/sh at the top of your script. sh might be bash on your system -- or it might not. It might even be dash on some systems, which has almost no features... Try #!/bin/bash
# 9  
Old 03-02-2011
Yea I can do redirection doing simple things like that. but yea it's from 2000 I think.
# 10  
Old 03-02-2011
Quote:
Originally Posted by linuxtraining
GNU bash, version 2.05.0(1)-release (sparc-sun-solaris2.9)
Copyright 2000 Free Software Foundation, Inc.
Okay, you're on Solaris. That means #!/bin/sh isn't bash. It's not even proper POSIX. You're getting Sun's weird old "backwards compatible" shell, barely younger than Disco. If you're allowed to use BASH, even the ancient version they have(you're using 2.0, we now have 4.0) is about 20 years newer.

The read + temporary file trick should work in either shell I think, but "<<<" definitely won't.

You should ask your prof which shell you're supposed to be using, since solaris #!/bin/sh is especially painful.

You should also be very grateful that you have GNU date. Smilie
# 11  
Old 03-02-2011
Yes it really is. I run Ubuntu and have the stuff I do I have to rewrite to wok on the Solaris shell to work.
# 12  
Old 03-02-2011
If I had to guess, I'd think that maybe expr is throwing up on the leading 0 in hour, but I have no way to test that, I don't have access to a solaris system anymore.
# 13  
Old 03-02-2011
I got it. It was pretty easy once I took a minuet to look over the code but now I'm trying to at a argument and assign it to a perimeter where it has to be a number. like 1-24 but i get errors.
# 14  
Old 03-03-2011
Please show the current version of your script and the exact error message which you received.


Slightly off-topic. On this vintage of Solaris surely Korn Shell would be more reliable ... and easier for others to present code which will run.
Code:
#!/usr/bin/ksh

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use of tr command to translate after 1st character of each line in a file

Hello, I have an input file contaning following data: < 12345;5454;77;qwert< yuyuy;ruwuriwru> yyyw; > 35353;68686;424242;hrjwhrwrwy< dgdgd; I have first character as '<' or '>'and after that one space is their in each line I just want to replace 1st space encountered after < or >... (3 Replies)
Discussion started by: abhi001cse
3 Replies

2. UNIX for Dummies Questions & Answers

How to translate multiple spaces into a single space using tr command?

I am trying to read a txt file and trying to translate multiples spaces into single spaces so the file is more organized, but whenever I try the command: tr ' ' ' ' w.txt The output is: tr: extra operand `w.txt' Try `tr --help' for more information. Can someone please help? :wall: ... (2 Replies)
Discussion started by: Nonito84
2 Replies

3. Shell Programming and Scripting

expr command help

I'm trying to check if a variable'd string is only one character and use that in an if statement the only way I could find is: $expr "${var}" : . # expr STRING : regrep where the "." is the grep wildcard for any single character. Whats wrong with my code here and is there a... (3 Replies)
Discussion started by: Tewg
3 Replies

4. Shell Programming and Scripting

expr command

Hi Can anyone explain me the usage of this command and the arguments used here and what will be the expected output : v_num=`expr nav_d_20100204_1759 : '*\(*\)'` what will be the value returned in v_num. Thanks in Advance!!! Regards Naveen Purbia (3 Replies)
Discussion started by: trying_myluck
3 Replies

5. Shell Programming and Scripting

Translate decimal into date

Hello, what can I do to convert a decimal number (001-366) into the day of the year it represent in the format of mm-dd-yyyy ? I know about the date +%j, it gives me the number for the current date, what about a reverse of this, is there such a thing? My number resides in a var, what can I do to... (3 Replies)
Discussion started by: gio001
3 Replies

6. UNIX for Dummies Questions & Answers

using the expr command

Hi friends how can i execute expr $va1 * $var2 provided i m not supposed to use '/' also the nglob variable is turned off. (4 Replies)
Discussion started by: ashishj
4 Replies

7. UNIX for Dummies Questions & Answers

expr command

hi guys.... i hava a command expr... where i m adding a value in a loop like Tc=`expr $Tc\+ $l` where Tc is declred as a variable and every time l contains a new vaue if Tc =0 initially and l =2 Tc should be equal to 0+ 2 and then l = 4 Tc = 2+4 and dispaly as 6 but after... (5 Replies)
Discussion started by: madhu_aqua14
5 Replies

8. Shell Programming and Scripting

date=`/usr/ucb/expr $date1 - 1`

Hi I need to subtract one day from date1=`/bin/date +%d` So I used date=`/usr/ucb/expr $date1 - 1` The only thing is if date1 is a single digit like 08, date will be 8 instead of 08. How can I avoid losing 0? Thanks for all your help!!! (4 Replies)
Discussion started by: whatisthis
4 Replies

9. UNIX for Advanced & Expert Users

Translate date value to normal date and backwards.

Hello, How do i translate datevalues in unix to normal dates. and how do i translate normal dates in to datevalues. I'm using the unix-date. Sample: 1067949360 to 4-11-03 12:36 and 4-11-03 12:36 to 1067949360 I want to built a script with a question to the user: give in date... (4 Replies)
Discussion started by: Frederik
4 Replies

10. UNIX for Dummies Questions & Answers

expr command

I am looking for the correct syntax on the expr command in UNIX. I have a script that I am building at the moment. the script is creating file1 that is an actual .sql file that is going inside the oracle database to get some information in there. It take that information, puts it inside another... (2 Replies)
Discussion started by: wolf
2 Replies
Login or Register to Ask a Question