Originally Posted by LoganK
Thank you, but most of that was done by help from my teacher. Unfortunately he threw this at us without really explaining how to do it. I'm still learning basic commands. I'd like to be able to at least have this finished and then go back and take it apart piece by piece to understand it.
So yes, I'm at "counts of the number of files that have a 1 character name" then "saves all the output to project1.data" then "Displays the contents of 'project1.data' to the user when the script completes"
I also don't know how to complete the script...I know I use "fi" right? I'm just not sure where everything goes. I'm completely clueless to be quite honest.
It would be a huge help if you could help me complete the script and then I can study how everything works before the next class. Thank you!!!
Here are the basics:
"ls" is used to list directory contents. If you give it an argument, like "ls /tmp/", it will list the contents of "/tmp" instead of your current directory. You can also give it wildcards, like "ls /tmp/*.log" or "ls ???.dat" to only list the files/dirs that match that pattern.
"*" means "match zero or more characters"
"?" means "match exactly one character"
So "?.txt" would match "a.txt", "b.txt", and so on, but not "ab.txt".
"wc" is a command to count the number of words in the input. If you add the "-l" flag, then it counts the number of lines instead.
"cat" is a command to dump out the contents of a file to the terminal.
"echo" is a command to print to the terminal, so "echo 5" will print "5" to the terminal, while "echo hello there" will print "hello there" to the terminal.
"|" is used to redirect the output of one command to the input of another command.
">" is used to redirect the output of a command to a file. So if you run "ls > ls.out", instead of printing the directory listing to the terminal, it will dump the directory listing into the file "ls.out"
These six simple commands are all that are required to complete your assignment.
To take one of your current commands:
"ls /tmp/*.log | wc -l"
That means, list all files in /tmp that match the pattern "*.log". Then send the output to "wc -l", which will count the number of lines. Since ls prints one file per line, this will effectively count the number of files that matched your pattern.
"fi" is the end of an if statement. If you don't have any if statements in your script then you shouldn't have any "fi" either. If you want to end your script, just stop typing, you don't need any specific command or letter combination to end.
Furthermore - any command you can put in a script, you can also run on the terminal by itself. There's nothing special about it being in a script, a script is just a sequence of commands. So just start experimenting. Type "ls", see what the output is. Type "ls /tmp/" and see what the output is. Type "ls /tmp/ | wc -l" and see what the output is. Scripting is not a black box where you have to come up with the perfect commands with the perfect syntax the first time, with no practice, no experimentation, and hope you're right or it'll blow up the machine. Just start experimenting. See what commands do what, see how to use them, see how to combine them, play with it and see what happens. If you have questions, use "man", as in "man ls", "man echo", "man cat", "man wc", etc.