handling filespec in bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting handling filespec in bash script
# 1  
Old 07-03-2008
handling filespec in bash script

hi there,
i just need a help handling the output of filespec in case has been picked

im writing a bash script similar to the command ls,
and ive done everything except handing the filespec which i spent more than 3 hrs and i coundn't figure out or find any on the net.

all what i need is when
*)
do the actual output of ls -l * that displays on command line.

Thanks all
# 2  
Old 07-04-2008
If you run myscript * the * will be replaced by the shell before running your script, so the parameters your script will actually see will be as if the script had been run using myscript file1 file2 file3 ....

You can only avoid this by turning off the shell's globbing features, or by protecting the parameters using quotes.

Similarly *) has special meaning in case statement; it matches any sequence of any character. Try '*') instead.
# 3  
Old 07-04-2008
Just as Annihilannic said.

I am sorry and don't want to offend, but why rewrite ls as a shell script? If it's a kind experimenting with parameters or handling files, maybe some other mechansim might be more suitable.
Ie. maybe we can suggest an alternative for your script if you describe what you try to do.
I know you didn't ask for - just a suggestion.
# 4  
Old 07-05-2008
Thanks for the help guys, actually im writing a script that does the same functions as ls command, i wrote a script that does -l option and -f to create a file and -d to create a directory, but i wasnt able to handle filespec with it, like handling * to make my script do the same as ls *
Thanks again.
# 5  
Old 07-06-2008
What if someone ran your script using scriptname *.dat? You couldn't write case statements to handle all those possibilities... you should leave it to the shell to look after glob expansion, that's its job.

Consider using getopts or similar to process the command-line parameters. It can differentiate between parameters that are filenames, and those that are switches (i.e. beginning with "-") and whether or not those switches have additional non-filename parameters that follow them.
# 6  
Old 07-06-2008
im just beginner with bash,
so i totally agree with you about what you said i wont be able to handle all filespec.

what do u suggest for me to handle at least outputting or listing the directory information, i.e how to make my script handle outputting just the output of ls *

i've tried making output of * as an array, but also i wasn't able to exceed my point.
# 7  
Old 07-06-2008
Show us the code and we may understand better what you're trying to achieve.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Help with shell script handling processes

Hello I have a file which has around 120 lines of commands. I am trying to write a shell script like which reads the 'command' file and executes line by line with some additional (common argument) with maximum 6 commands active at a time. Each of these commands when executed takes time... (5 Replies)
Discussion started by: JackyShane_36
5 Replies

3. Shell Programming and Scripting

Help me add Error Handling to my script

Hi all, I have some sections of a script that I am trying to add error handling to. Basically if it returns any error, just continue. This is for a deployment script that i am writing to assist in the deployment of scripts out to other systems. At the top of my KSH script i added this... (5 Replies)
Discussion started by: nitrobass24
5 Replies

4. Shell Programming and Scripting

BASH - Handling background processes - distributed processing

NOTE: I am using BASH and Solaris 10 for this. Currently in the process of building a script that has a main "watcher" daemon that reads a configuration file and starts background processes based on it's global configuration. It is basically an infinite loop of configuration reading. Some of the... (4 Replies)
Discussion started by: dcarrion87
4 Replies

5. UNIX for Dummies Questions & Answers

File handling in bash shell scripting

i am new to shell scripting and stuck at one place in my program. i am reading data from one structured file and extracting some data from particular lines and then writing into the output file. In that reading input file line by line from while loop. while read line do rectype=line... (7 Replies)
Discussion started by: reeta_shri
7 Replies

6. Shell Programming and Scripting

Help with Error Handling on Script

Hi, I need your guys help again. I run a script which check for some process status in a loop. when i check the process some of the process could throw an error, how can i check that inside my script. Thanks, RR (3 Replies)
Discussion started by: rrb2009
3 Replies

7. Shell Programming and Scripting

Help with handling columns in bash

Hi all, I've tried to look answer from various places but cannot get for my problem. I have a file which is tab delimited: column1 column2 column3 1 10 one 2 100 two 3 9 three 4 100... (7 Replies)
Discussion started by: JSStone
7 Replies

8. Shell Programming and Scripting

File handling with bash shell scripting

Hi all, Can anyone guide to get tricks for file handling in bash shell? Thanks in advance. Thanks Deepak (2 Replies)
Discussion started by: naw_deepak
2 Replies

9. Shell Programming and Scripting

File handling in Script

Hi All, How can we handle file operation in scripts. I have written a script that run ok otherwise however the "Cat" operation leaves a process open on the box. Command is like cat "${LASTFILENAME}" | /usr/xpg4/bin/awk -F, '{do{if ($3 == "100" && $4 == "300" && $170 ~ /^abc/) { ... (2 Replies)
Discussion started by: raman1605
2 Replies

10. UNIX for Dummies Questions & Answers

Handling input from a ls in a script

I'm trying to write a script that will handle the input from the ls command in my script so I can then manipulate the data. For example, I want to capture the output of the ls command in my script and then do a differences between the filename received in to another directory. ls |... (1 Reply)
Discussion started by: spookyrtd99
1 Replies
Login or Register to Ask a Question