Issue nesting variables in csh.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue nesting variables in csh.
# 1  
Old 11-07-2017
Issue nesting variables in csh.

The variables given are already defined ($file1-$file3, $obsid1-$obsid3, and $n=3). When I go to run the code, the terminal outputs "Missing }." I believe the error is with the nesting of variables. It would save a lot of time getting this while loop working.

Code:
set i = 1     

while (${i} <= ${n})
dmcopy "${file${i}}[energy=500:7000&&(x,y)=circle(${c},${r})][bin sky=1]" ./img/${obsid${i}}_5_70_b1.img      

@ i++     

end

This is the snippet I believe has the "Missing }." error somewhere in it. I can't seem to find anything wrong. Does csh support nesting like this or will I need to try something else?
# 2  
Old 11-07-2017
(Skipping the compulsary "don't use csh" reply.)
No, the assembly of a variable like ${file${i}} doesn't work.
You can use a list, for example
Code:
set files=( $file1 $file2 $file3 )
set i=1
echo "$files[$i]"

Or, as the last resort, try eval
Code:
set i=1
eval set file=\$file$i
echo "$file"

# 3  
Old 11-07-2017
Quote:
Originally Posted by MadeInGermany
(Skipping the compulsary "don't use csh" reply.)
Smilie
# 4  
Old 11-08-2017
What is a good alternative that functions the way I need it to?
# 5  
Old 11-08-2017
Code:
set files=( "$file1" "$file2" "$file3" )
set obsids=( "$obsid1" "$obsid2" "$obsid3" )

set i=1

while ($i <= $n)
  dmcopy "${files[$i]}[energy=500:7000&&(x,y)=circle(${c},${r})][bin sky=1]" "./img/${obsids[$i]}_5_70_b1.img"

  @ i++

end


Last edited by MadeInGermany; 11-08-2017 at 03:03 PM.. Reason: one more quotes added
# 6  
Old 11-09-2017
The above solution worked.
This User Gave Thanks to ojdefdidit For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read variables from a text file for use in csh script

Hello, I have a text file (say, declarevars.txt) that contains multiple lines that are essentially meant to be variable declarations: set arr1 = (var1a var1b var1c) set arr2 = (var2a var2b var2c) . . . I want to be able to read this text file within a csh (sorry) script and have that... (2 Replies)
Discussion started by: arjaydj
2 Replies

2. Shell Programming and Scripting

Nesting backticks

I'm trying to make a dialog window that prints the output of grep that takes the output of find. Unfortunately my nested backticks don't work. Here is the dialog window: dialog --stdout --title "test" --backtitle "test" --msgbox "Test:\n `grep -l "${tablica}" `find $string``" 16 60I think I... (2 Replies)
Discussion started by: Starting_Leaf
2 Replies

3. Shell Programming and Scripting

How to use ifdef for bash variables in csh environment?

Hi Guys, I have a a bash script and i am exporting a variable in it. I am calling a csh script from this bash script. The variable "ABC" will be visible in csh script. ks.bash export ABC = abc ./kp.csh ab.csh echo $ABC setenv ABC =cde (i want to assign this value to ABC only if... (4 Replies)
Discussion started by: vdhingra123
4 Replies

4. 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

5. Shell Programming and Scripting

Max number of environment variables in Csh

Anyone knows what is the max limit of number of environment variables in Csh? I have a script that when run causes the shell to stop responding to any command like: ls /bin/ls: Argument list too long. And I guess the reason is I passed the max limit for number of environment variables... (1 Reply)
Discussion started by: mohy
1 Replies

6. Shell Programming and Scripting

Csh Problem using spaces in string variables

I have done something like this set phases = "a b" set phases = "phases="$phases echo $phases I get phases=a instead of phases=a b (3 Replies)
Discussion started by: kristinu
3 Replies

7. Google Chrome OS

Case Nesting

sdfdefgsrg (2 Replies)
Discussion started by: frankycool
2 Replies

8. UNIX for Dummies Questions & Answers

For loop control with two variables in csh shell

Hi All How can i control for loop with two different variables in csh shell Regards Nikhil (1 Reply)
Discussion started by: Nikhilindurkar
1 Replies

9. Shell Programming and Scripting

sh and csh issue

Hi I like to assign a command string to a variable to execute. In this case, set sshexec_parent_pid="ps -ef | grep $$ | awk '/bash -c/ {print $3}' | sort | head -1;`" echo $sshexec_parent_pid ; But I can't seem to get it to work. It gives me sshexec_parent_pid: Undefined variable. ... (2 Replies)
Discussion started by: mpc8250
2 Replies

10. Shell Programming and Scripting

How to pass CSH variables up to the parent?

Hi .. I have a dynamic script called from a programming language called Powerhouse (4GL). The module, called QUIZ, allows the user to call shell commands from within it... i.e. !rm -f mipss156t2cmd1.bat mipss156t2tmp1.txt !printf '#!/bin/csh\n' > mipss156t2cmd1.bat !printf 'setenv... (0 Replies)
Discussion started by: ElCaito
0 Replies
Login or Register to Ask a Question