How to count filenames after getting them with "set"?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to count filenames after getting them with "set"?
# 1  
Old 03-17-2010
How to count filenames after getting them with "set"?

Hi,

I have a .ksh script, and I read files from a directory with "set" command:

Code:
set B*.txt

Means I can now assign with

Code:
file1=$1

the first filename found to a variable file1.

How can I count how many files it has found with "set"?

Thanks,
Michael
# 2  
Old 03-17-2010
Code:
echo $#

# 3  
Old 03-17-2010
Thanks!

Do you maybe also now how to manage, that the filenames are assigned to a variable in a loop, like:

Code:
set B*.txt
i=1
c=$#
x=$((c+1))
echo "$x"

while [[ $x -gt i ]] ; do
_ftpfile$i="$"$i
echo "$_ftpfile$i"
i=$((i+1))
done

the first echo returns, that x = 4, and as long x is not gt. than i(=1), it should create a variable _ftpfile$i (_ftpfile1, _ftpfile2, _ftpfile3) with the value of the set command, means the filename in $i (which should be $1, $2 and $3).

here's the output:

4
awkb.ksh[13]: _ftpfile1=$1: not found
1
awkb.ksh[13]: _ftpfile2=$2: not found
2
awkb.ksh[13]: _ftpfile3=$3: not found
3


---------- Post updated at 05:01 PM ---------- Previous update was at 04:44 PM ----------

ok maybe thats a new question for all ... so thanks so far for help on that one ...
# 4  
Old 03-17-2010
Code:
eval _ftpfile$i="$"$i

# 5  
Old 03-17-2010
do you maybe also know how to chmod the files? Smilie
# 6  
Old 03-17-2010
Code:
chmod 744 file

Check chmod in manual for more options
# 7  
Old 03-17-2010
I think it does not work that way within the same loop when creating the variables in the ksh?
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Why awk print is strange when I set FS = " " instead of FS = "\t"?

Look at the following data file(cou.data) which has four fields separated by tab. Four fields are country name, land area, population, continent where it belongs. As for country name or continent name which has two words, two words are separated by space. (Data are not accurately... (1 Reply)
Discussion started by: chihuyu
1 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. Shell Programming and Scripting

BASH find filenames in list that match certain "pattern."

I guess by "pattern," I mean something different from how that word is defined in the Linux world. If you take $ to mean a letter (a-z) and # to mean a number (0-9), then the pattern I'm trying to match is as follows: $$$##-####-###-###.jpg I'd like to write a script that reads in a list of files... (4 Replies)
Discussion started by: SilversleevesX
4 Replies

5. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

6. Programming

Differece between "env" and "set" command

Hi, Please clarify what is the difference between "env" and "set" command. I guess set will display the system variables and user defined variables. Thanks Sweta (1 Reply)
Discussion started by: sweta
1 Replies

7. Shell Programming and Scripting

Problem with "set" and "awk"

Hi, i'm programming on /bin/csh and i need to get the number extracted by this: set ppl_kn = $(awk '{ field = $6 } ; END{ print field }' < ppl_LM_kn.ppl ) and the output is: "Illegal variable name." Please anyone can help me what's wrong? Thanks in advance (2 Replies)
Discussion started by: tmxps
2 Replies
Login or Register to Ask a Question