what can i do with shell?
i have learned how to program in shell. but i do not know what should i do with it? how can i program with it? how to practice?
thanks in advance!:) |
if you want to learn shell scripting, check out the bash scripting howto at tldp.org
|
Quote:
thanks!!!!! |
I would start by making some utilities for monitoring your system, parsing log files, automating backups with rsync, or tar, and anything else. That should be a good start. Oh and you might also want to try and create install scripts for files.
|
Quote:
|
Quote:
1) I would decide what you want to backup. 2) Decide when to backup. 3) Where are you going to backup to. (My preference has always been to get a 500gb hard drive.) 4) Lets break our backups into folders. Say Mon, Tue, Wed, Thr, Fri. Week1, Week2. I use week1 and week2 so that I can go back as far as two weeks in my full backups. 5) Lets do some sanity checks. First part of your script will be to see if rysnc is installed. so you will want to check for that and if it fails then stop and create a log with the error. This should get you started. What I would do is then use your book for reference. As for a system to start out with I would use debian because to me it is simple. Someother good ones are Slackware, Fedora, Ubuntu, CentOS, my favorite right now is arch. If all you are trying to do is a little bash scripting I would say Fedora, Ubuntu, CentOS. Debian, Slackware, and Arch normally have some burn in time where you have to setup some things. |
You know, people don't usually start with "I want to do some scripting" and then search for something to script. They usually begin with a problem or need; something like, "I want to be able to take a folder full of mp3 files, convert them to .ogg format with metadata intact, rename them according to the track metadata, then sort them all into separate folders based on the artist and filename". They then go out and script a series of commands to do just that.
All a script really is is a sequence of commands designed to automate some process. You want practice? Take any cli command you know how to use (using ffmpeg to convert audio files to ogg vorbis, for example) and simply see if you can automate it to process a whole directory of files at once. Then you can start replacing the hard-coded commands with user-input choices (such as selecting ogg vs mp3 output). You can get gradually more and more complicated as you go on (e.g. how do I vary the bitrate? How can I have user-selected filenames?, having an option to move/remove the original file, etc.). The sky's the limit. It all comes down to your imagination and scripting experience. So really, you just need to get down and dirty. You can't learn scripting by reading a book. Just decide on something you want to accomplish and start writing. It'll be slow going at first, but that's how you learn. The first script I ever created was a "remove directory" script that asked me if I wanted to either remove the whole thing, including contents, at once, or to confirm the deletion of each file separately. I made it because I was paranoid about deleting a directory with "rm -r" and losing important stuff inside. But you know something? Even though I made my script ask me some questions first, at the heart of it there's still just the plain old "rm -r" command. I still use it today, but I probably should go back and rewrite it soon, because I've learned so much more about scripting since then that I'm almost embarrassed to look at the code for it. :) |
Quote:
thanks what should i do now? i want to write a script to change all the file names of one folder. but i faild. could you guide me this? thanks |
if you don't know why you're doing something, don't do it! This approach makes no sense at all...
|
Quote:
thanks in advance. |
Quote:
|
First get used to using the console. Cd to different directories; list files; use less & cat to examine text files. Get comfortable in the shell environment. Use the * and ? wildcards with ls. Become familiar with using a text editor. There are several to choose from.
The most common commands are provided by the coreutils package. It contains commands such as cp, mv, ls, cat. Scan through the info manual for coreutils. It may be easier reading it in the konqueror browser. You can do this by entering info:coreutils in the address bar. You can read manpages the same way, e.g. man:mv |
That's what the texts and tutorials are for. You don't just jump into big scripts, you start small and learn the basics.
You first have to know how to use individual commands on their own. Only when you're familiar with the tools can you start using scripting functions to combine them. For your "rename files" script, you need a few things: First you need a renaming program. mv will do nicely. If you don't know how to use mv to rename a file, then you have to stop right there and learn that first. Second, you need a way to run the command multiple times on different data input. The "for loop" scripting process is probably the one you'll want to use. Third, you need to be able to input the name changes you want, and for that you'll need to use variables, particularly the command positional parameters ($1, $2) and perhaps the read command if you want interactive input. You may also wish to do some arithmetical processing if you want to generate sequentially-numbered files, the output of which will be stored in a variable. Finally you'll want to use the "echo" command to provide some user-readable feedback. Again, if you don't know what all of these things are, you have to do more studying. Your final script will probably be something that takes an input string from the command line (when starting the script or interactively), stores it in a variable, then uses that variable in the output of the mv command. And the mv command will be sitting in a for loop that takes each filename in the directory as input and runs the command on it. I often recommend LinuxCommand.org as a good place to start learning the shell and scripting. Don't just read it, go through each page step-by-step and actually do the things he shows you in the examples. Try the commands out yourself in a console of your own. Play with them until you really understand the concepts behind them. After a while you should start to naturally recognize how you can combine them to do things that are not in the tutorials. |
That is a pretty good site. I really like the flow and layout. Course I started out with this book and reference it a lot. http://www.amazon.com/Linux-Shell-Sc...4541634&sr=8-6 but then moved to perl. Only problem with perl is that when you stop using it, you seem to forget alot of the things it can do.
|
Quote:
this is the script i have wrote, and do not know what should i do next: #!/bin/bash directory=/home/zsf/pictures for i in $directory/* thanks |
All times are GMT -5. The time now is 02:21 AM. |