Script help
How do u write a script that provides a file, let say "MyFiles", that contains a list of all the files in the current directory and displays on the screen the number of files present in the current directory??
thanx |
Re: Script help
Quote:
In two ways: ls -1A > MyFiles ls -1A | wc -l wc counts word,lines,characters from the input . -l gives you only the lines man bash man wc have fun |
thanx for ur help. What does man bash, man wc mean?
|
man is a unix command which stands for manual, it gives you access to reference manual of all the commands you have on your systems, and a lot of other things.
Code:
man wc You can move in with the arrows, move one page forward with space , move one page backwards with 'b' , quit with 'q' , search by typing '/' followed by what you want to search (then 'n' for next found, 'p' for previous found) -> you can sometimes also try : Code:
apropos wc Code:
apropos -e wc -> an also Code:
info coreutils wc http://www.indiana.edu/~uitspubs/b017/ |
It is really great that u r helpin me get to grips with linux. Could you help me with a few more scripting questions? :)
There are a couple of things I wanna b able to do in linux put am findin it difficult: (1) How do i write a script that moves all the files that end in ".txt" from the current directory to another (target) directory. I want this script to produce a text file ("filesCopied") that lists all files that have been moved. (2) How do i write a script that reads in ten numbers (either one at a time during script execution or as parameters) and prints to the screen the sum of these numbers? (3) How do i alter the previous script to allow it to work for arbitrary lists of numbers. Thanks alot nx5000! |
Just who's homework assignment are we doing here?
LOL - For #1, did you mean to "copy" or "move" - since you wanted the filename generated to be"filesCopied", I'll assume you meant copy. #1 Starts below #!/bin/bash [ -d ${1} ] && cp $( ls *.txt | tee filesCopied ) ${1} || echo "Invalid directory name entered". --------------------------------------------------- #2 starts below #!/bin/bash viNumParams=${#} viMathExpr="0" [ ${viNumParams} -gt 10 ] && { echo "Only 10 parameters are allowed, you have entered ${viNumParams}" exit 1 } viCounter=1 while [ ${viCounter} -le ${viNumParams} ] do vsMathExpr=${vsMathExpr}" + ${viCounter}" viCounter=$(( ${viCounter} + 1)) done while [ ${viCounter} -le 10 ] do echo "Enter numeric for number ${viCounter} parameter: \c" read viNumeric vsMathExpr=${vsMathExpr}" + ${viNumeric}" viCounter=$(( ${viCounter} + 1)) viNumeric=0 done echo "Here is the completed math expression: "${vsMathExpr} echo "Here is the answer: "$(( ${vsMathExpr} )) --------------------------------------------------- #3 starts below #!/bin/bash viNumParams=${#} viMathExpr="0" viCounter=1 while [ ${viCounter} -le ${viNumParams} ] do vsMathExpr=${vsMathExpr}" + ${viCounter}" viCounter=$(( ${viCounter} + 1)) done vsNumeric="0" while [ "${vsNumeric}" != "" ] do echo "Enter numeric for number ${viCounter} parameter, press enter to end list: \c" read vsNumeric [ "${vsNumeric}" != "" ] && vsMathExpr=${vsMathExpr}" + ${vsNumeric}" viCounter=$(( ${viCounter} + 1)) done echo "Here is the completed math expression: "${vsMathExpr} echo "Here is the answer: "$(( ${vsMathExpr} )) ---------------------------- HTH, Nawar |
All times are GMT -5. The time now is 09:30 PM. |