LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-29-2009, 06:37 AM   #1
comeatmanish
LQ Newbie
 
Registered: Feb 2009
Posts: 21

Rep: Reputation: 0
Shell scripting ....


Hi All,

I'm trying to write interactive shell script.
which will ask user to provide path where the files would be stored.

Since this path contains "/" (for.eg. /home/msk/current/log)
how can i make this readable using read.
Following is the script

#!/bin/bash

echo "Enter the path to search"
read DIR
HOMEMS=$DIR

for X in $DIR/*

do

awk -F';' '{print $1}' >> /home/msk/output.file

echo -n "#"

done


Please guide me.

Regards,
MSK
 
Old 09-29-2009, 07:39 AM   #2
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by comeatmanish View Post
Hi All,

I'm trying to write interactive shell script.
which will ask user to provide path where the files would be stored.

Since this path contains "/" (for.eg. /home/msk/current/log)
how can i make this readable using read.
Following is the script

#!/bin/bash

echo "Enter the path to search"
read DIR
HOMEMS=$DIR

for X in $DIR/*

do

awk -F';' '{print $1}' >> /home/msk/output.file

echo -n "#"

done


Please guide me.

Regards,
MSK
Guide you how? What did you expect, what did you get, and how do they differ?

Code:
echo "Enter the path to search"
read DIR
HOMEMS=$DIR
What's wrong with:

Code:
echo -n "Enter the path to search: "
read HOMEMS
It's a bit difficult to help you when you don't say what you want to happen and how that differs from what you got.
 
Old 09-29-2009, 07:42 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by comeatmanish View Post
I'm trying to write interactive shell script.
which will ask user to provide path where the files would be stored.

Since this path contains "/" (for.eg. /home/msk/current/log)
how can i make this readable using read.
Following is the script

#!/bin/bash

echo "Enter the path to search"
read DIR
HOMEMS=$DIR

for X in $DIR/*

do

awk -F';' '{print $1}' >> /home/msk/output.file

echo -n "#"

done
I don't understand what you are asking and the script you show does not seem to relate to your question.

Specifically, what do you mean by "Since this path contains "/" (for.eg. /home/msk/current/log) how can i make this readable using read."? The read command reads from stdin (standard input, usually the terminal); it has nothing to do with making directories readable which is done by the chmod command.

In the script, in the loop you do exactly the same thing each time through because the only thing that changes is $X and it is not used in the loop.

Actually the loop will hang because there is no input specified on the awk -F';' '{print $1}' command so it reads stdin; the awk command will wait for input.

When posting code, it is easier to read if you use code tags (that's a link so you can easily find out about them).
 
Old 09-29-2009, 04:18 PM   #4
AngTheo789
Member
 
Registered: Sep 2009
Posts: 110

Rep: Reputation: 24
Not sure what you want to achieve! Possibilities are:
1. ask directory as input, then copy a bunch of known files to that location
2. ask directory as input, then copy all files from that location to a known other location
3. ask directory as input, then read a list of filenames from a file passed as a script argument, and copy those files to the given location

Programming or scripting is difficult, if it is not known what needs to be done exactly!
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Terminal functions for shell scripting with Shell Curses LXer Syndicated Linux News 0 03-27-2008 12:50 AM
SHELL scripting/ shell functions mayaabboud Linux - Newbie 6 12-26-2007 09:18 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 04:32 PM


All times are GMT -5. The time now is 08:10 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