LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell scripting .... (https://www.linuxquestions.org/questions/linux-newbie-8/shell-scripting-758421/)

comeatmanish 09-29-2009 05:37 AM

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

lutusp 09-29-2009 06:39 AM

Quote:

Originally Posted by comeatmanish (Post 3700406)
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.

catkin 09-29-2009 06:42 AM

Quote:

Originally Posted by comeatmanish (Post 3700406)
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).

AngTheo789 09-29-2009 03:18 PM

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!


All times are GMT -5. The time now is 04:45 AM.