Perl to read user input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl to read user input
# 1  
Old 04-30-2015
Perl to read user input

I am creating a bash that uses perl . The below code closes before the input is entered. If I run the perl as a .pl it is fine. What am I doing wrong? Thank you Smilie.

Code:
 
#!/bin/bash

cd 'C:\Users\cmccabe\Desktop\wget'
wget -O getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv

print "Enter ID: ";
my $string = <>;

open FILE, "getCSV.txt" or die $!;

while (<FILE>) { print if /$string/i }

close FILE;

# 2  
Old 04-30-2015
Code:
my $string=<STDIN>;

# 3  
Old 04-30-2015
Still closes the bash after the getCSV is downloaded. Thank you Smilie.

Code:
#!/bin/bash
cd 'C:\Users\cmccabe\Desktop\wget'
wget -O getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv
print "Enter ID: ";
my $string=<STDIN>;
open FILE, "getCSV.txt" or die $!;
while (<FILE>) { print if /$string/i }
close FILE;

# 4  
Old 04-30-2015
bash runs bash scripts. perl runs perl scripts. Why are you trying to run perl code with bash? You need to call perl to do that.
# 5  
Old 04-30-2015
The wget is not right in the perl . Thank you Smilie.

Code:
#!/usr/bin/perl
use strict;
my $result = 'wget -O getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv');

print "Enter ID: ";
my $string = <>;

open FILE, "getCSV.txt" or die $!;

while (<FILE>) { print if /$string/i }
close FILE;

In bash the code below works I am just learning bash however and not sure on other functions yet but am reading up. Thanks.

Code:
#!/bin/bash

cd 'C:\Users\cmccabe\Desktop\wget'
wget -O getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv
 
{
    printf "\n\n"
    printf "What is the id: "; read id
         [ -z "$id" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && return
         [ "$id" = "end" ] && printf "\n Leaving match function." && sleep 2 && return
}

I am going to close this thread and open a new one sticking to bash . Thank you Smilie.

Last edited by cmccabe; 04-30-2015 at 02:23 PM.. Reason: closed thread
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using input from read to allow user to designate a specific volume

I am attempting to script the creation of MacOS installation flash media using read to allow the user to designate the name of the volume and store it in the variable VOLNAME. When I run the script, and input the name of the volume, I get the error: ': not a valid identifier: `VOLNAME... (4 Replies)
Discussion started by: kevinamygrayson
4 Replies

2. Shell Programming and Scripting

Unable to read user input inside a loop

Hi, This query is a part of a much more lengthy script. I wish to look for all the files in a folder named "data" which in this case has two files i.e. plan.war and agent.properties. For all the files found under data I wish to ask the user as to where they wish copy the files to. Below,... (14 Replies)
Discussion started by: mohtashims
14 Replies

3. Shell Programming and Scripting

Shell read command is not waiting for user input

Hi, i am working on one automation , for that i have writing one shell program that take user input in "while read line" block. but read command is taking value that is readed by While block. while read line; do command 1; command 2 echo -n "Do you want to continute > " read rsp... (2 Replies)
Discussion started by: ranvijaidba
2 Replies

4. Shell Programming and Scripting

BASH - read does not wait for user input in some circumstances

Hello. I am running 2 scripts : script_1 and script_2 These scripts are run as root Script 2 contains : #!/bin/bash # # ~/bin/script_2 # E_BAD_PARAM=115 # date2stamp () { date --date "$1" +%Y-%m-%d___%H:%M:%S } # USER_NAME=$1 NB_PARAM=$# PARAM0=$0 (2 Replies)
Discussion started by: jcdole
2 Replies

5. Shell Programming and Scripting

Using read to prompt for editable user input in Bash 3

Below is a simple script to prompt for user input while suggesting an editable default value at the prompt: shortname=user1 read -e -i $shortname -p "Please enter the username you would like to add: " input USERNAME="${input:-$shortname}" Please enter the username you would like to add:... (3 Replies)
Discussion started by: woodson2
3 Replies

6. Shell Programming and Scripting

Help with Bash piped while-read and a read user input at the same time

Hi I am new to writing script and want to use a Bash Piped while-read and read from user input. if something happens on server.log then do while loop or if something happend on user input then do while loop. Pseudocode something like: tail -n 3 -f server.log | while read serverline || read... (8 Replies)
Discussion started by: MyMorris
8 Replies

7. Shell Programming and Scripting

Solaris- Read command from user input

I need to write a bourne shell script (solaris 10) that accepts input from the user. The input will be a command- any command like ls/ pwd/ mv etc. After the input is read, the shell must execute the command supplied by the user. I know we use read to play with user inputs. Just not sure how to... (2 Replies)
Discussion started by: PDManc
2 Replies

8. UNIX for Dummies Questions & Answers

How to read a line of text from user input?

Hiii I wanna a read a line of text from standard input. The user enter data like this way name phone_no month1_salary month2_salary that is user enter the name ,phone no and salary of 2 months in a single line by giving spaces. I wanna add the 3rd and 4th fields ...ie add both... (4 Replies)
Discussion started by: krishnampkkm
4 Replies

9. UNIX for Dummies Questions & Answers

getline to read input from a user

Hi, The gcc compiler has warned about using gets(), so I've been trying my hand at getline. Problem is that I've been able to read from a file, but what I really need is to read from a user's input. I want to use getline like a scanf() command, but I can't figure what to substitute for the fp... (6 Replies)
Discussion started by: sdsd
6 Replies

10. UNIX for Dummies Questions & Answers

read user input from within a wile loop that is being fed from below

hi! i need to do a ksh script that uses a wile loop that is fed form below while read line do some things done < myfile inside the while loop i need to read user input to ask the user what he wants to do, but "read" reads the file, and not the standard input while read line do ... (2 Replies)
Discussion started by: broli
2 Replies
Login or Register to Ask a Question