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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
11-18-2003, 07:02 AM
|
#1
|
Member
Registered: Aug 2003
Location: Seffner, FL
Distribution: Mint
Posts: 82
Rep:
|
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.
|
|
|
11-18-2003, 07:59 AM
|
#2
|
LQ Guru
Registered: Jan 2001
Posts: 24,149
|
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.
|
|
|
11-18-2003, 08:12 AM
|
#3
|
Member
Registered: Aug 2003
Location: Seffner, FL
Distribution: Mint
Posts: 82
Original Poster
Rep:
|
great i'll give it a shot. gonna try to write my first "hello world" tonite ;-)
|
|
|
11-18-2003, 08:40 AM
|
#4
|
Member
Registered: Nov 2003
Location: Land of the Rising Sun!
Distribution: Fedors Core 3, Red Hat 9, Mandrake 8.1
Posts: 52
Rep:
|
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.
|
|
|
11-18-2003, 12:36 PM
|
#5
|
Member
Registered: Aug 2003
Location: Seffner, FL
Distribution: Mint
Posts: 82
Original Poster
Rep:
|
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.
|
|
|
11-18-2003, 12:38 PM
|
#6
|
Moderator
Registered: May 2001
Posts: 29,415
|
Just post what you've got?
|
|
|
11-18-2003, 12:47 PM
|
#7
|
Member
Registered: Aug 2003
Location: Seffner, FL
Distribution: Mint
Posts: 82
Original Poster
Rep:
|
#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
|
|
|
11-18-2003, 12:48 PM
|
#8
|
Member
Registered: Aug 2003
Location: Seffner, FL
Distribution: Mint
Posts: 82
Original Poster
Rep:
|
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
|
|
|
11-18-2003, 12:53 PM
|
#9
|
Senior Member
Registered: Jun 2003
Distribution: Debian/other
Posts: 2,104
Rep:
|
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
|
|
|
11-18-2003, 01:14 PM
|
#10
|
Member
Registered: Aug 2003
Location: Seffner, FL
Distribution: Mint
Posts: 82
Original Poster
Rep:
|
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
|
|
|
11-18-2003, 01:17 PM
|
#11
|
Moderator
Registered: May 2001
Posts: 29,415
|
# 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"
|
|
|
11-18-2003, 01:36 PM
|
#12
|
Member
Registered: Aug 2003
Location: Seffner, FL
Distribution: Mint
Posts: 82
Original Poster
Rep:
|
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.
|
|
|
11-18-2003, 04:52 PM
|
#13
|
Member
Registered: Nov 2003
Location: Land of the Rising Sun!
Distribution: Fedors Core 3, Red Hat 9, Mandrake 8.1
Posts: 52
Rep:
|
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
|
|
|
11-18-2003, 04:53 PM
|
#14
|
Member
Registered: Aug 2003
Location: Seffner, FL
Distribution: Mint
Posts: 82
Original Poster
Rep:
|
yes i made it executable by typing
chmod u+x script_name
|
|
|
11-18-2003, 05:34 PM
|
#15
|
Member
Registered: Nov 2003
Location: Land of the Rising Sun!
Distribution: Fedors Core 3, Red Hat 9, Mandrake 8.1
Posts: 52
Rep:
|
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"
|
|
|
All times are GMT -5. The time now is 12:09 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|