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.
|
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. |
great i'll give it a shot. gonna try to write my first "hello world" tonite ;-)
|
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
|
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.
|
Just post what you've got?
|
#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 :( |
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 |
If you've got a list of file names then maybe something like ??
Code:
#!/bin/bash |
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 |
# 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" |
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 :confused: |
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 |
yes i made it executable by typing
chmod u+x script_name |
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 09:21 PM. |