Variable value inconsistency on BASH and CSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variable value inconsistency on BASH and CSH
# 1  
Old 04-08-2009
CPU & Memory Variable value inconsistency on BASH and CSH

May God never give you the bane of working on Solaris.
Now, I am trying to run this simple shell script:

Code:
 #!/bin/sh
    
    input="a
    b
    c"
    data="123"
        
    while read eachline
    do      
       data="$data$eachline"
    done <<  EOF
    $(echo "$input")
    EOF
    
    echo "$data"
    exit 0

On RHEL(BASH) I receive output as expected i.e "123abc", however, on Solaris I receive just "123".

After fair bit of googling, I realized that Solaris is forking a process for code inside the while loop and hence the variable's($data) value is not reflected on the outside of while loop.

Any hope to make this code compatible on both platforms would be greatly appreciated.
# 2  
Old 04-08-2009
no offense, but i've been working on solaris for 20 years. it works fine.

your logic and implementation of this problem is a little obscure.

to me, it looks like your output ~should~ be this:

123a123b123c

since it looks like you're appending data AND input each time.

the problem may be that using the HERE document creates a subshell,
wherein variable changes are not exported.

So. I think a better sample of your input data and expected output would
be in order and really help us to find a solution.
# 3  
Old 04-08-2009
Quirkasaurus,
$data="123"
I want this to be concatenated with $input:
So the expected output would be:

"123abc".

This is happening as expected on BASH and also on KSH. CSH, like you said is creating a subshell and hence the variable value is not reflected.

I was hoping for inputs on some other approach to replace the current so that I can loop on the contents of a variable, line by line.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Changing script from csh to bash

Hello Guys I have a script working fine on csh, but I would like to change it to bash, how I should change this command to be able to work as bash script. :wall: if ( $fsw > "0" ) then foreach swath ( `awk 'BEGIN {for (i='$fsw';i<='$lsw';i++) printf ("%s\n", i) }'` ) ## work to be done... (2 Replies)
Discussion started by: jiam912
2 Replies

2. Ubuntu

error LD: undefined variable while changing shell from bash to csh

Hi, i am a beginner in ubuntu. my default shell is bash. everytime i try to change the shell with command "csh", i get a message (probably an error message). after i get into c-shell, when i try to execute a c shellscript, then it showed the same message. any idea about what is this about or any... (1 Reply)
Discussion started by: Avinash Nayak
1 Replies

3. Shell Programming and Scripting

How to access the bash variables in csh

Hi, I am having a primary script which is Bash based. I am calling a csh script from it. Now, their are some variables defined in my bash script which i need in csh. I am unable to do so. Is it possible ? (2 Replies)
Discussion started by: vdhingra123
2 Replies

4. Shell Programming and Scripting

Need a script to convert csh to bash

Hi, Can anyone give me a script to convert csh to bash? or any key points which can help me to do so as i am new to it. (3 Replies)
Discussion started by: vineet.dhingra
3 Replies

5. Shell Programming and Scripting

Importing env from csh to bash

Hi All, In my account with csh shell, there are lots of env variables set and I want to import those all to bash in one stroke, is there any way to do it ? Thanks, D (1 Reply)
Discussion started by: Deei
1 Replies

6. UNIX for Dummies Questions & Answers

Running CSh scripts in Bash

Hi, I have some csh scripts and I want to run them in .bashrc. I use these techniques without any success: . test.csh or csh test.csh The first one assumed that the scripts is a bash script, so showed me errors. The second one finished without giving proper result. Can anybody offer... (6 Replies)
Discussion started by: mjdousti
6 Replies

7. Shell Programming and Scripting

Bash one liner to CSH

Hello all, I have a Bash command I'm using on one system that replaces text in filenames, I'ts not working on another system that uses the Csh shell. Can anyone tell me what I need to do when i run for f in *;do mv $f ${f/text1/text2};done on the CSH shell i get ""Missing }."" (7 Replies)
Discussion started by: mike171562
7 Replies

8. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

9. Shell Programming and Scripting

different shell csh bash

I'm always having to work in the cshell, but occasionally want to run a command using bash. is that possible? I know I could write a shell script and call bash at the begining with #!/usr/bin/bash and then my command, is there another way? (1 Reply)
Discussion started by: ajp7701
1 Replies

10. Shell Programming and Scripting

From bash to csh and zsh

... Am I glad to find this forum (and vBulletin too, nice!).. OK, here's my issue. I have been handballed a bash script, not pretty but functional. I need to change to csh and zsh. For the csh I have the basics (e.g., such as change if/fi to if/endif, quote the variables, and bracket commands).... (10 Replies)
Discussion started by: lev_lafayette
10 Replies
Login or Register to Ask a Question