LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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
 
LinkBack Search this Thread
Old 11-18-2003, 07:02 AM   #1
pcdebb
Member
 
Registered: Aug 2003
Location: Brandon, FL
Distribution: Mageia 2
Posts: 81

Rep: Reputation: 15
shell scripting


Ok I now am learning shell scripting. I feel a little held back with how the text is teaching me, and my instructor is basically going from the same book. does anyone have any useful links I can use to get more comfy with shell scripting? if it matters it is/will be in bash.
 
Old 11-18-2003, 07:59 AM   #2
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 194Reputation: 194
Always one of the sites and howto's I use when I need some answers and examples: http://www.tldp.org/LDP/abs/html/

Its the one howto that has tons of examples to use and go from to help out in understanding what the different parts of scripts do, etc.
 
Old 11-18-2003, 08:12 AM   #3
pcdebb
Member
 
Registered: Aug 2003
Location: Brandon, FL
Distribution: Mageia 2
Posts: 81

Original Poster
Rep: Reputation: 15
great i'll give it a shot. gonna try to write my first "hello world" tonite ;-)
 
Old 11-18-2003, 08:40 AM   #4
tiger3
Member
 
Registered: Nov 2003
Location: Land of the Rising Sun!
Distribution: Fedors Core 3, Red Hat 9, Mandrake 8.1
Posts: 52

Rep: Reputation: 15
Try this site, look at "Contents and Navigation" there you will find the modules look through them to find what you need to help. http://www.upscale.utoronto.ca/Gener...nux/index.html

Last edited by tiger3; 11-18-2003 at 08:42 AM.
 
Old 11-18-2003, 12:36 PM   #5
pcdebb
Member
 
Registered: Aug 2003
Location: Brandon, FL
Distribution: Mageia 2
Posts: 81

Original Poster
Rep: Reputation: 15
oh geesh all of those links are terribly overwhelming to me. right now i'm looking for simple stuff. for example i'm working on taking user input ,and the input is filenames. i use a command (find or grep) to find the file and if it exists then show the last mod time of the file. when i use grep nothing happens, if i use find i get a hit, so i'm sort of stuck there. i think i'm not using the right options or something? i accept the input fine because right now i echo the input so i know i'm doing that right.
 
Old 11-18-2003, 12:38 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,534
Blog Entries: 51

Rep: Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604
Just post what you've got?
 
Old 11-18-2003, 12:47 PM   #7
pcdebb
Member
 
Registered: Aug 2003
Location: Brandon, FL
Distribution: Mageia 2
Posts: 81

Original Poster
Rep: Reputation: 15
#accept filename as argument, and show last modification time of file
#if it exists, or show message if it doesnt exist.

echo "enter filename: "
read file1
find $HOME -name $file1 -print


this seems to list the path and file, but i'm confused at getting all the info (the last modified time is what i'm after). reading the chapters seem so easy but getting the script to work is entirely different
 
Old 11-18-2003, 12:48 PM   #8
pcdebb
Member
 
Registered: Aug 2003
Location: Brandon, FL
Distribution: Mageia 2
Posts: 81

Original Poster
Rep: Reputation: 15
i tried the if then fi statement but that didnt seem to work. at first i had this:

#accept filename as argument, and show last modification time of file
#if it exists, or show message if it doesnt exist.

echo "enter filename: "
read file1

if grep "$1"; then
echo "file found" #here will list mod time
else
echo "that file does not exist"
fi
echo "Last modification time is " #just filler, will get here
 
Old 11-18-2003, 12:53 PM   #9
Skyline
Senior Member
 
Registered: Jun 2003
Distribution: Debian/other
Posts: 2,104

Rep: Reputation: 45
If you've got a list of file names then maybe something like ??

Code:
#!/bin/bash

echo "Please type a list of filenames :"

read -a filenames

for i in ${filenames[*]}

do
............
............
done
 
Old 11-18-2003, 01:14 PM   #10
pcdebb
Member
 
Registered: Aug 2003
Location: Brandon, FL
Distribution: Mageia 2
Posts: 81

Original Poster
Rep: Reputation: 15
ok i find reference to find a file that was done x days ago, can i just show when the last time when it was modified or accessed instead of x days? Skyline, that loop didnt work for me

I did however just figure out what was wrong with my loop. apparently the book is a misprint as it wasnt listing the syntax correctly
 
Old 11-18-2003, 01:17 PM   #11
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,534
Blog Entries: 51

Rep: Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604Reputation: 2604
# Ask for name, test if var is empty, exit if, else search. The "iname" is case insensitive, the printf prints out the M-time local to you with the full filename behind it. I made it print quotes so it's easy to spot misplaced spaces and if you feed it to something else it won't break on spaces. Null termination (-fprint0 or -print0) do the same:

echo "Enter filename: (will search in "$HOME")"; read file
test -z file && exit 1 || find "$HOME" -type f -iname "${file}" -printf "%t \"%p\"\n"
 
Old 11-18-2003, 01:36 PM   #12
pcdebb
Member
 
Registered: Aug 2003
Location: Brandon, FL
Distribution: Mageia 2
Posts: 81

Original Poster
Rep: Reputation: 15
ok now i'm going crazy, i entered the test line in a file and did it and it worked, i insert in in my script and it DOEST wrk and i entered it exact. WHY?!!?!?!?!?!?!?!?

NM. guess it required verbal foul language to make it work

Last edited by pcdebb; 11-18-2003 at 01:42 PM.
 
Old 11-18-2003, 04:52 PM   #13
tiger3
Member
 
Registered: Nov 2003
Location: Land of the Rising Sun!
Distribution: Fedors Core 3, Red Hat 9, Mandrake 8.1
Posts: 52

Rep: Reputation: 15
Check to make sure your script file is executable.....

ls -l script_name # will tell you if it is -rwxr-xr-x

chmod 755 script_name # will change the parameters

This should fix it if it worked from the command line. Once you create a file you must make it executable then to execute it type

./script_name
 
Old 11-18-2003, 04:53 PM   #14
pcdebb
Member
 
Registered: Aug 2003
Location: Brandon, FL
Distribution: Mageia 2
Posts: 81

Original Poster
Rep: Reputation: 15
yes i made it executable by typing

chmod u+x script_name
 
Old 11-18-2003, 05:34 PM   #15
tiger3
Member
 
Registered: Nov 2003
Location: Land of the Rising Sun!
Distribution: Fedors Core 3, Red Hat 9, Mandrake 8.1
Posts: 52

Rep: Reputation: 15
Are you trying to allow the user to enter the file name at the prompt?
If so I think you need to remove the newline from the end of echo with the -n option.

echo -n "Enter filename: (will search in "$HOME")"
read file
test -z file && exit 1 || find "$HOME" -type f -iname "${file}" -printf "%t \"%p\"\n"
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 03:32 PM
Shell Scripting again yaadhav Linux - Newbie 8 08-04-2005 10:21 AM
shell scripting markus1982 Linux - General 2 05-20-2003 07:42 AM
Help with Shell Scripting. eggoz Linux - General 2 04-21-2003 01:15 PM


All times are GMT -5. The time now is 10:46 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration