user3675541
user3675541

Reputation: 23

for and file command in shell

I have studied shell recently and I saw a sample code in the book and here it is:

File.sh

#!bin/bash

file_count=0;
for file in *
do
  let file+=1
done

echo "There are $file_count files in folder"

I tried this code and result is so weird.

I has three files in folder, File.sh, Test.sh, Child.sh but file_count value is 6 in result.

I print value of file and the result is:

child.sh
child.sh~
File.sh
Test~
Test.sh
Test.sh~

Wonder why this happened.

Upvotes: 1

Views: 28

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174816

The file names ended with ~ are backup files created by some famous text editors (like gedit). Once you open a file through such text editors, it would automatically creates a backup for each file you opened.

Upvotes: 1

Related Questions