Hi,
There is a variable f_name, it store some file names.
Value of f_name=a.sql b.sql c.sql.......
like this.
want to count how many file name the var f_name stores.
Without using loop is there any command to count that.
Hi,
There is a variable f_name, it store some file names.
Value of f_name=a.sql b.sql c.sql.......
like this.
want to count how many file name the var f_name stores.
Without using loop is there any command to count that.
can you please clarify whether it is a variable or it is a directory which stores list of files.
Depends on the shell you are using:
(assuming elements separated by white spaces)
[zsh]
$ f_name="a.sql b.sql c.sql"
$ print ${#${(z)f_name}}
3
[ksh93 & bash]
$ f_name_a=($f_name);printf "%d\n" "${#f_name_a[@]}"
3
If none of the above works:
$ (f_name="a.sql b.sql c.sql";set -- $f_name; printf "%d\n" $#)
3
# f_name="a.sql b.sql c.sql"
# echo $f_name|tr " " "\n"|wc -l
3
Another one:
echo $f_name|awk '{print NF}'
wc -w ---> will return the no of words, why can't you use this option...
echo $fname|wc -w