LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 09-02-2010, 08:04 PM   #1
asidrain
LQ Newbie
 
Registered: Sep 2010
Posts: 1

Rep: Reputation: 0
need help with bash scripting


have a script that I need to make for class and looking for a little bit of help.
Code:
#!/usr/bin/bash
# 1.1 use the "id" or maybe "whoami" command to show id
echo  "Name  `whoami`"
#1.2 # of command line arguments
echo number of command line arguments is $#
#2.1 print statement telling users whether file is found or not
#upto 5 arguments
if [ -a $1 ] ;  then
        echo $1 exists
#2.4 check whether file is writable
        if [ -w $1 ] ; then
                echo $1 is writable
        else
                echo $1 is not writable
        fi
#2.3 check whether file is executable
        if [ -x $1 ] ; then
                echo $1 is exacutable
        else
                echo $1 is not exacutable
        fi
else
        echo $1 does not exist
fi
I need to find out how to tell if the file was modified and date it was, also need help finding out the size of the file if it exists.
 
Old 09-02-2010, 08:19 PM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,606

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Hi,

have a look at the manpage of
Code:
man stat
stat provides the info you need.
 
Old 09-03-2010, 10:26 PM   #3
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Debian, Mint, OpenBSD
Posts: 11,346
Blog Entries: 12

Rep: Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731
Machtelt Garrells writes great manuals. Check out his Intro to BASH scripting.

Last edited by frankbell; 09-03-2010 at 10:26 PM. Reason: grammar
 
Old 09-04-2010, 12:25 AM   #4
ruthinman
LQ Newbie
 
Registered: Sep 2010
Posts: 8

Rep: Reputation: 0
Wink

well it wouldn't be fair if we wrote the script for you but a few hints might not be too bad.

ls -l is a command that lists a directory (or a file, if given as an argument) in long form so you can see more details of it. (try it)

that might help steer you in the direction you need to go without giving you all the answers.
 
Old 09-05-2010, 02:45 PM   #5
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,053

Rep: Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881Reputation: 881
Here is some more stuff that doesn't directly solve your problems:

Quote:
Originally Posted by asidrain View Post
#!/usr/bin/bash
So, whatever system you are using, it uses bash?


Quote:
#1.2 # of command line arguments
echo number of command line arguments is $#
#2.1 print statement telling users whether file is found or not
#upto 5 arguments
So, if there is a maximum of 5 arguments, what happens if someone enters six arguments. OK, let me be more specific, what do you want to happen if someone enters six (or more) arguments, and does the script that you have written, so far, do it?

Quote:
if [ -a $1 ] ; then
echo $1 exists
#2.4 check whether file is writable
if [ -w $1 ] ; then
echo $1 is writable
else
echo $1 is not writable
fi
#2.3 check whether file is executable
if [ -x $1 ] ; then
echo $1 is exacutable
else
echo $1 is not exacutable
fi
else
echo $1 does not exist
fi
It looks as if you were intending to do something with $1 (let's say, first that you test that $1 is not empty (and what if it is empty?) and once you have done that, move on to the next value. There is no sign of anything happening that might happen after the first $1.

Last edited by salasi; 09-05-2010 at 02:47 PM. Reason: undoing an accidental delete
 
  


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
bash scripting help fernfrancis Linux - Newbie 4 05-10-2010 02:57 AM
bash scripting ZAMO Linux - General 1 12-04-2008 03:53 AM
Reading a bash variable in bash scripting problem freeindy Programming 3 11-27-2008 03:29 AM
Bash scripting saje Linux - Newbie 4 08-22-2007 09:03 PM
Bash scripting NSKL Linux - General 2 06-08-2002 01:10 PM


All times are GMT -5. The time now is 03:56 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration