Sed, bash problems migrating from Cray to GNU/Linux


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed, bash problems migrating from Cray to GNU/Linux
# 1  
Old 02-09-2014
Sed, bash problems migrating from Cray to GNU/Linux

So, I have a series of ASCII files, all named something like mrkxxxxz.tmp (say, mrk1001z.tmp, mrk1002z.tmp, mrk1003z.tmp,...) -- these are .tmp files created by a large simulation program, and each different .tmp file represents a different parameter space used in the simulation). The simulations were originally run on a Cray, and on said platform, I would run the following shell script (which I call simbatch) to process them, and send them off to a FORTRAN application called 'mark':

Code:
# construct the mark command to run a set of mrkxxxxz.tmp files
echo $@
for i in $@ do
   #echo $i
   out=`echo $i | sed 's/z\./y\./'`
   #echo $out
   res=`echo $i | sed 's/z\./x\./'`
   #echo $res
   vc=`echo $i | sed 's/z\./v\./'`
   #echo $vc
   tmp=`echo $i | sed 's/z\./s\./'`
   #echo $tmp
   echo `date` >>'$tmp'
   nohup mark i='$i' o='$out' r='$res' v='$vc' >&'$tmp' &
done

Now, this works fine on the Cray, but under Linux, nada. I get all sorts of errors:

Code:
'/simbatch: line 5: syntax error near unexpected token `out=`echo $i | sed 's/z\./y\./'`

I'm *guessing* this is a problem with 'quoting' things, but I'll be darned if I've hit on the right combination.

Pointers to the obvious?

Thanks in advance!
# 2  
Old 02-09-2014
Hi, the problem is here:
Code:
for i in $@ do

Which should be
Code:
for i in "$@"; do

or
Code:
for i in "$@"
do

Your old shell (on the Cray) may have happened to accept it, but it is not correct.

--
Also note that because of the single quotes, the variables will not be expanded:
Code:
nohup mark i='$i' o='$out' r='$res' v='$vc' >&'$tmp' &

If you need them expanded, use double quotes instead of single quotes...


--
Since "$@" is the default you can also just omit it:
Code:
for i do

or
Code:
for i
do

This:
Code:
for i ; do

is officially not allowed in the Posix specification, but most modern shells do not have a problem with it, unlike earlier Bourne Shells.

Last edited by Scrutinizer; 02-09-2014 at 04:37 PM..
These 3 Users Gave Thanks to Scrutinizer For This Post:
# 3  
Old 02-10-2014
Perfect -- thanks *very* much. I had guessed my way through things and by brute force had gotten some things working, but your reply cleared everything up perfectly.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed problems - Bash Script

Hi I keep getting the following error sed: -e expression #1, char 32: unterminated `s' command sed: -e expression #1, char 35: unterminated `s' command sed: -e expression #1, char 35: unterminated `s' command whenever I use the following bash script #! /bin/bash... (2 Replies)
Discussion started by: spbr
2 Replies

2. Shell Programming and Scripting

Converting from Linux bash (GNU) to Solaris script syntax errors

Original script written on CentOS 6.3 with GNU bash 4.1.2 Destination system is Solaris 9 with GNU bash 2.05 (not changeable by me) I have a script written on the linux side but now we need to provide a version to another site that "doesn't like linux". I've been going through changing the ] or... (13 Replies)
Discussion started by: oly_r
13 Replies

3. AIX

Help migrating bash script to AIX machine

hey frnds I am trying to migrate a bash script over the AIX machine , but was getting error with ps and read commands, so I make the few changes in script and have also chnaged the shell from bash to ksh below is my script... (5 Replies)
Discussion started by: sumit_saxena
5 Replies

4. Linux

Migrating RCS from HP-UX to Linux

Hello all, We would be migrating from HP-UX 11 to Red Hat Linux 5 shortly. On HP-UX we've been using RCS (Revision Control system). On RHEL I think there is an equivilant utility called Subversion..Is there a way to export the current contents from RCS in HP-UX and import it into Linux's... (2 Replies)
Discussion started by: luft
2 Replies

5. HP-UX

Migrating from HP UX to LINUX/SOLARIS- which one is more preferable?

Hi all, We have an application that is running on HP-UX operating system (11i). the application is built using C, C++, ProC and ProC++ codes. we have been given two choices for migration: LINUX and SOLARIS. I would like to know the differences between the three OS and which OS to prefer... (3 Replies)
Discussion started by: pb0069950
3 Replies

6. Programming

Project ideas for GNU/Linux C and BASH development

Hello everyone... I'm trying to find an interesting project to work on for my master thesis. I like GNU/Linux C development and BASH scripting. Please give me any idea that flashes in your mind. I thank you in advance... (3 Replies)
Discussion started by: jonx
3 Replies

7. Shell Programming and Scripting

Subtracting time with awk - BASH/Debian GNU Linux

I'm sure this is simple and I've been looking at examples for days on end but can't seem to come to grips with awk. What I have: mplayer -v dvd:// -identify -vo null -ao null -nolirc -nojoystick -frames 0 2>/dev/null >> /tmp/MplayerOut ChapterStart=($(grep CHAPTERS: /tmp/MplayerOut |sed... (3 Replies)
Discussion started by: rickenbacherus
3 Replies

8. Ubuntu

Migrating from Unix to Linux

Is there a way to migrate username password from Freebsd 6.1 to Linux Ubuntu 8.04. I am using the server as a email server running postfix and using imap. Is there a way to transfer the usernames and password. I have transferred all the Maildirs but I am getting uid errors and gid errors even after... (2 Replies)
Discussion started by: rbizzell
2 Replies

9. Shell Programming and Scripting

problems with sed and bash. Escaped characters ?

Hi, I'm writing a long script for bash (on RHEL 5.0) to execute many commands. So, my idea is to create a function to deal with error checking and logging (see ceckoutput() below). This works with all commands except for sed. I think it may be a problems with escaped characters. So I did the... (4 Replies)
Discussion started by: macL
4 Replies
Login or Register to Ask a Question