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, 04:50 AM   #31
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Distribution: Mint/MATE
Posts: 3,010

Rep: Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287

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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:21 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
Open Source Consulting | Domain Registration