how to prompt the user to enter an array in tcsh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to prompt the user to enter an array in tcsh
# 1  
Old 12-06-2011
how to prompt the user to enter an array in tcsh

Hello,

I am writing a script that requires the user to enter a string of numbers:
Code:
 
ex: 134 345 865 903

This command only allows for one variable to be entered:
Code:
 
set "var" = $<

and than once I got the array I want to change it to a list with each input on a different line:

Code:
 
ex:
134
345
865
903

Does anyone know how to accomplish this in tcsh.

Thanks Smilie

Last edited by smarones; 12-06-2011 at 05:24 AM..
# 2  
Old 12-06-2011
If you want the user input to be an array then I think you may have the double quotes in the wrong place.

Instead of
Code:
set "var" = $<

Try
Code:
set var = "$<"

For example:
Code:
startover:
echo Please enter a string of numbers eg 134 345 865 903
set num = "$<"
if ( "$num" == "" ) then
 echo "You need to enter a list of numbers"
 goto startover
endif

You should be able to create a list of your array easy enough. Give it a try Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Auto enter for prompt messages

Hello everybody, I am coding a script, that allow the user to enter some information using prompt messages, i.e: sEpisode=1 read -e -i "$sEpisode" -p "Start download from episode: " downloadFrom sEpisode="${downloadFrom:-$sEpisode}" This code allows the user to set the download from... (4 Replies)
Discussion started by: Abu Rayane
4 Replies

2. Shell Programming and Scripting

Script to prompt user to enter data

Hi All I have a script that moves files from one dir to another dir based on date, but I would like to change it in a way that whoever is going to run to enter the dates in which files will be removed. This is my script: #!/bin/sh touch -mt 201302250000 /tmp/ref3 touch -mt 201302282359... (14 Replies)
Discussion started by: fretagi
14 Replies

3. UNIX for Dummies Questions & Answers

issue with my prompt on tcsh

Hi, issue with my prompt, other gets their name, my comes with command number. Why? {118} /home/markb > echo $SHELL /bin/tcsh {119} /home/markb > echo $SHELL /bin/tcsh {120} /home/markb > my .cshrc has this.... set prompt="%{\0330;%n@%M : %~%L \007%} `pwd` >%{\033 ... (3 Replies)
Discussion started by: samnyc
3 Replies

4. UNIX for Dummies Questions & Answers

scp not working because of prompt (AIX, tcsh)

Hello, I have this problem: I have a server to which I ssh, and it has a special prompt request. The prompt is done by a ?prompt command. It is fine with SSH, since the prompt I guess gets some input, but when I use SCP, the copy always fails. So, I was wondering if there is maybe a... (1 Reply)
Discussion started by: lastZenMaster
1 Replies

5. UNIX for Dummies Questions & Answers

shell (tcsh) prompt gets reset on every cd

Hi, I type in my shell: set prompt="(%M) %c%b%# " to get something like: a/b/c> this works, but only partially. every time I move to to a different directory (i.e. 'cd <some dir>'), the prompt is reset. Meaning, when I 'echo $prompt' after setting the prompt I get the correct prompt,... (8 Replies)
Discussion started by: yuvalbn
8 Replies

6. Solaris

Console - root command prompt displayed twice after hitting enter

Dear All, I hope you can help me. I have a pair of E2900's I've inherited. Both running Solaris 9. Both have LOM> consoles. The problem I'm experiencing only occurs when connected to the /dev/console tty. Whenever I hit 'Enter' for a new line, I receive two new lines: - myhost# ... (11 Replies)
Discussion started by: aleith
11 Replies

7. Shell Programming and Scripting

How to enter commands to the command prompt in a program

Hey, So I'm trying to write a program in unix to automate a process for my astrophysics research. Basically I want the program to prompt the user for some information and store the entered string of text as a variable. I know how to do this. This is where I need help: Now lets say I have a... (4 Replies)
Discussion started by: freemoniez
4 Replies

8. Shell Programming and Scripting

tcsh/csh: set prompt in production to color red

Hi folks This is our prompt at the moment oracle@pinkipinki:/opt/oracle> grep 'set prompt' .cshrc set prompt = "$user@`uname -n`:$cwd> " We wish to have in production the same prompt, but red. Howto do that? I tried a lot a internet manuals, but it doesn't work. (1 Reply)
Discussion started by: slashdotweenie
1 Replies

9. Shell Programming and Scripting

enter password at prompt during a script?

I'm using rsync with the "-e ssh" option so of course it asks for a password using a prompt. Is there a way to tell a script to expect a prompt, wait for it, and give a password when it arrives? There is a way to give rsync a password as part of its options using a file, but it only works with... (2 Replies)
Discussion started by: davidstvz
2 Replies

10. Shell Programming and Scripting

How to enter if-then condition on command prompt/line ?

Hi I have some trouble entering if-then condition in a single line on a command prompt in csh. Could someone show how does one do that ? eg: source .cshrc; cd $dir; pwd; test -d $backup_dir; if then mkdir -p ${backup_dir}; echo inside loop; fi; echo outside loop; mv -f... (3 Replies)
Discussion started by: mpc8250
3 Replies
Login or Register to Ask a Question