How to echo counter to file in bash

MLSC

The content of file:

$ cat count.txt
0

This is my script:

counter=`cat count.txt`
value=`let counter++`
echo $value > count.txt

But the syntax is wrong...

Could you help me over this thread? How can I increase counter and echo it to file?

anubhava

You can use BASH's (( and )) construct for arithmetic operations:

echo 0 > count.txt
counter=$(<count.txt)

((counter++))
echo $counter > count.txt
cat count.txt
1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to echo a variable following a string in bash?

From Dev

In bash script, is it possible to echo something into the beginning of file?

From Dev

How to print #!/bin/bash using echo command

From Dev

Bash script to read from a file and echo

From Dev

echo special characters to a file in bash

From Dev

How to make echo compatible with read in bash?

From Dev

How to assign the result of echo to a variable in bash script

From Dev

Bash: How to end printf or echo with a \ and then a new line

From Dev

how to use echo with find in bash?

From Dev

Echo multiline string into file bash

From Dev

BASH file mass rename with counter

From Dev

How to get bash file to echo differently based on user input?

From Dev

How to use subprocess.run to echo (bash) inside another file

From Dev

BASH file mass rename with counter

From Dev

How to get bash file to echo differently based on user input?

From Dev

How to echo commands to other file

From Dev

How does bash echo print its arguments?

From Dev

How to echo counter to file in bash

From Dev

How to echo #!/ using shell or bash

From Dev

How do I get a bash script to echo itself into a new file?

From Dev

How to move forward in a line in bash with echo?

From Dev

How to overwrite file using echo?

From Dev

How to find text in a file in bash and echo the output and add it to a variable

From Dev

How evil is this: echo bash >> .bashrc

From Dev

Elegant solution to echo to either stdout or file in bash

From Dev

Bash - How to do a normal counter?

From Dev

bash echo into another file not working

From Dev

bash loop file echo to each file in the directory

From Dev

How to check if file exists and echo it?

Related Related

HotTag

Archive