Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-28-2012, 02:52 PM   #1
Registered: Aug 2009
Posts: 41

Rep: Reputation: 1
How to read a file and use that to start a process


I do lot of things with license, we have so many different application which requires different license for each. I need to find out how to pass the file name from a directory on to script?

This is what I did so, please help on the XYZ below.

# If lmgrd is already executing, don't re-execute it.


## XYZ - some server have three file, some of them have 10 files here.  
#I need to find out how to do ls take the name of the file to pass it here. 


case $1 in
        if [ -x $LMGRD ]
        if [ -f $LICFILE ]
        $LMGRD -c $LICFILE -l $LOGFILE
        if [ -x $LMGRD ]
        $LMGRD -x lmdown
        echo "usage: /etc/init.d/lmgrdsh {start|stop}"
Old 03-28-2012, 06:48 PM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
I think you may need to describe the situation with a few more words than
this; I for one can't make too much sense of your request.

How is the script invoked, where does the "directory" come into the picture?

Old 03-29-2012, 08:58 AM   #3
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,837

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
If you need to work on multiple files, you should use an array, rather than a single scalar variable.

Or are you trying to match a single file out of a directory to use? If so, you'll need to explain your requirements in more detail. Give us an example of the directory contents, which file you need to match, and how you want to use it.

In addition, I'd like to offer some general comments regarding your script:

QUOTE ALL OF YOUR VARIABLE SUBSTITUTIONS. You should never leave the quotes off a parameter expansion unless you explicitly want the resulting string to be word-split by the shell. This is a vitally important concept in scripting, so train yourself to do it correctly now. You can learn about the exceptions later.

It's recommended to use ((..)) for numerical tests, and [[..]] for string tests and other complex expressions. Don't use the old [..] test unless you specifically need POSIX-style portability.

Clean, consistent formatting makes code readable and more easily debuggable. Indent all your sub-commands, and separate logical sections with whitespace. Add comments anywhere the code isn't completely obvious (and remember, what seems obvious to you now will not be a year or so down the line).

Many people also think that it's more readable to place the "do/then" keywords on the same line as the "for/while/until/if" keywords, as it more clearly separates the outside block from the inside block.

for var in <list> ; do

	if [[ "$var" == "foo" ]]; then

Environment variables are generally all upper-case. So while not absolutely necessary, it's good practice to keep your own user variables in lower-case or mixed-case, to help differentiate them.
1 members found this post helpful.


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
[SOLVED] how to read a PID from a text file and kill the corresponding process sneakyimp Linux - Newbie 3 06-30-2010 02:52 PM
nfsd lots read/write, file/process causing problem mfitzpat Linux - Newbie 2 05-11-2010 02:58 PM
help with c program to read each line from text file, split line , process and output gkoumantaris Programming 12 07-01-2008 01:38 PM
How can read from file.txt C++ where can save this file(file.txt) to start reading sam_22 Programming 1 01-11-2007 06:11 PM
How can I create a pid file from a backgournd process that I start? Hackiller Linux - General 3 05-12-2004 03:37 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:15 AM.

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