LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 10-18-2016, 03:50 AM   #31
MadeInGermany
Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 313

Rep: Reputation: 123Reputation: 123

If you have cd'd into the $1 directory, you list the files with *
($i/* lists the file in the $1 directory when you have not done a cd.)
Code:
#!/bin/bash

rows=""
name=""
if [ -d "$1" ] ; then
   cd "$1"
else
   echo "Invalid directory name - exiting. Usage: ${0##*/} <directory>"
fi
for f in *
do
...
Or simply trust that a failing cd will give an appropriate error message.

Code:
#!/bin/bash

rows=""
name=""

cd $1 || exit

for f in *
do
...

Last edited by MadeInGermany; 10-18-2016 at 04:05 AM. Reason: In the simple cd the $1 must not be quoted
 
  


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
Creating script which find the file with the less rows NewGuy95 Linux - Newbie 1 10-17-2016 01:25 PM
[SOLVED] Find a File delete out different file in same directory HardenedCriminal Linux - Security 9 06-04-2015 07:28 PM
find the largest and smallest file in a directory and sub directory schandran Programming 5 05-06-2015 09:53 AM
how to find match between two rows of column in same file using PERL genetist Linux - Newbie 3 07-13-2013 11:17 AM
a2ps: cannot find file `c0419bt_.afm': No such file or directory rg3 Slackware 5 08-02-2009 03:11 PM


All times are GMT -5. The time now is 01:11 AM.

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