LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-29-2007, 06:17 AM   #1
dalicros
LQ Newbie
 
Registered: Jan 2005
Posts: 4

Rep: Reputation: 0
input into bash script(reading path)


hi,
I have got problem with one of mine scripts.
In this script I need to get the path to file frome user. I simply use read -p "File : " PATH_TO_FILE, this works fine, until the path is too long, then the read returns an error. Any ideas how to fix this?

I also have another problem with this, is there any way how to be able to use auto-adding the file name during read?

Thanks for any help.
 
Old 05-29-2007, 08:23 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
It's always good to be specific when you describe a problem.

Please post (as a reply in this thread) a short script that demonstrates the problem, the path that you enter, and the exact error message you get.

For example, I tried this script:

Code:
#!/bin/sh

read -p "File: " PATH_TO_FILE
echo $PATH_TO_FILE
and I entered this path (300 characters):

Code:
/000000010/000000020/000000030/000000040/000000050/000000060/000000070/000000080/000000090/000000100/000000110/000000120/000000130/000000140/000000150/000000160/000000170/000000180/000000190/000000200/000000210/000000220/000000230/000000240/000000250/000000260/000000270/000000280/000000290/000000300
and got no error at all. It echoed the path correctly.

A good thing to do is to use the script command to record all input and output. Then take the file typescript and post it as code (going to advanced posting mode and using the # button), like this:

Code:
wally:~$ script
Script started, file is typescript
wally:~$ cat tuesday.sh
#!/bin/sh

read -p "File: " PATH_TO_FILE
echo $PATH_TO_FILE

wally:~$ tuesday.sh
File: /000000010/000000020/000000030/000000040/000000050/000000060/000000070/000000080/000000090/000000100/000000110/000000120/000000130/000000140/000000150/000000160/000000170/000000180/000000190/000000200/000000210/000000220/000000230/000000240/000000250/000000260/000000270/000000280/000000290/000000300
/000000010/000000020/000000030/000000040/000000050/000000060/000000070/000000080/000000090/000000100/000000110/000000120/000000130/000000140/000000150/000000160/000000170/000000180/000000190/000000200/000000210/000000220/000000230/000000240/000000250/000000260/000000270/000000280/000000290/000000300
wally:~$ exit
Script done, file is typescript
Once we see this, we can get a better handle on your problem.

Oh. And. What do you mean by auto-adding, and can you give an example of what that might be like?
 
Old 05-29-2007, 09:47 AM   #3
dalicros
LQ Newbie
 
Registered: Jan 2005
Posts: 4

Original Poster
Rep: Reputation: 0
ooops it seems, the problem was not in read ...
the path got by read is in my script passed to dcfldd like bellow :

read -p "Image file (ex. WinXP_Lin.img): [default.img] " SOURCE_FILE;
if [ ${#SOURCE_FILE} -eq 0 ]
then
SOURCE_FILE="default.img"
fi
dcfldd if=/storage/${SOURCE_FILE} of=/dev/hda bs=512 sizeprobe=if

the block size was set to 8192 and this caused the problem, when /storage was NFS type.

auto-adding is meant (I was not sure how to translate it into english ) as you write for example 3 letters from the name of file and then press tab key and the file name is filled. Any idea how to make this in read?

Thanks for help.
 
Old 05-30-2007, 06:54 PM   #4
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
What you mean by auto-adding we refer to as "filename completion". Use the -e switch, like this:

Code:
#!/bin/sh

read -e -p "Enter the file name: " filename
echo I have read "$filename"
Then you can use tabs for filename completion in the normal manner.

Hope this helps.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash: How to read tab character when reading input new_to_bash Programming 7 12-09-2006 07:31 PM
reading file, bash script marri Programming 3 11-15-2004 09:13 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
User input using a BASH script... causticmtl Programming 5 07-13-2003 09:59 PM
bash-script input aizkorri Programming 7 07-08-2003 06:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration