# User Input Shell Script

**URL:** <https://community.unix.com/t/user-input-shell-script/270530>\
**Category:** Shell Programming and Scripting\
**Created:** [July 29, 2010, 6:12pm UTC](https://community.unix.com/t/user-input-shell-script/270530 "2010-07-29T18:12:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sureshcisco](https://community.unix.com/letter_avatar/sureshcisco/32/6_449c533f586939b6e5f246632a46421f.png) [@sureshcisco](https://community.unix.com/u/sureshcisco)\
**Post date:** [July 29, 2010, 6:12pm UTC](https://community.unix.com/t/user-input-shell-script/270530/1 "2010-07-29T18:12:31Z")

</div>

Hello

I am trying to create a user input shell scipt. The objective is user should enter the circuit number and the input is saved in a log file. If the user does not enter anything then the question should prompt it until the circuit no. is entered.  
Can any one please correct the code below. Appreciate your response.

```nohighlight
 
#!/bin/sh
path=/var/log/circuit.txt
reply=" "

while ($reply ne ' ')
{
echo "Enter the Circuit Number:"
chomp ($reply = <STDIN>) >> $path
}

```

---

<div class="post-metadata">

**Author:** ![jpradley](https://community.unix.com/letter_avatar/jpradley/32/6_449c533f586939b6e5f246632a46421f.png) [@jpradley](https://community.unix.com/u/jpradley)\
**Post date:** [July 29, 2010, 6:26pm UTC](https://community.unix.com/t/user-input-shell-script/270530/2 "2010-07-29T18:26:14Z")

</div>

while ($reply ne ' ') : you are testing if the string $reply contains a space.  
I think you want to test if it contains nothing.

---

<div class="post-metadata">

**Author:** ![sureshcisco](https://community.unix.com/letter_avatar/sureshcisco/32/6_449c533f586939b6e5f246632a46421f.png) [@sureshcisco](https://community.unix.com/u/sureshcisco)\
**Post date:** [July 29, 2010, 6:29pm UTC](https://community.unix.com/t/user-input-shell-script/270530/3 "2010-07-29T18:29:57Z")

</div>

I made the change but I get the below errors:

```nohighlight
./circuit.sh: line 7: syntax error near unexpected token `$reply'
./circuit.sh: line 7: ` chomp ($reply = <STDIN>)'

```

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [July 29, 2010, 7:22pm UTC](https://community.unix.com/t/user-input-shell-script/270530/4 "2010-07-29T19:22:49Z")

</div>

```nohighlight
 
#!/bin/sh
path=/var/log/circuit.txt
reply=

while [-z "$reply"]
{
  printf "Enter the Circuit Number: "
  read reply
}

```
