| |

VerySource

 Forgot password?
 Register
Search
View: 29|Reply: 5

Ask a shell. . .

[Copy link]

1

Threads

3

Posts

4

Credits

Newbie

Rank: 1

Credits
4

 China

Post time: 2020-3-21 22:00:01
| Show all posts |Read mode
The data in the a.ini file is as follows:

1
2
3
4
5
6
. . . .


There is a program that needs to get the data of each row in turn, and then fetch the data of the next row after the execution is completed. How to write this loop?
Reply

Use magic Report

0

Threads

10

Posts

8

Credits

Newbie

Rank: 1

Credits
8

 China

Post time: 2020-7-6 09:15:01
| Show all posts
This program is very simple, read a newline to indicate the end of a line.
Reply

Use magic Report

0

Threads

18

Posts

12

Credits

Newbie

Rank: 1

Credits
12

 China

Post time: 2020-7-6 09:30:01
| Show all posts
#!/bin/sh
content=`cat a.ini`
sum=0
for num in $content; do
#your operations
let sum=$sum+$num
echo $num
done

echo $sum
Reply

Use magic Report

1

Threads

3

Posts

4

Credits

Newbie

Rank: 1

Credits
4

 China

 Author| Post time: 2020-7-23 18:00:01
| Show all posts
Thank you upstairs in advance

I am SOLARIS csh here, let’s not be used
let: not found

Also, the data of a.ini is irregular
901
345
567
. . . . . .
Reply

Use magic Report

0

Threads

1

Posts

2

Credits

Newbie

Rank: 1

Credits
2

 China

Post time: 2020-7-25 15:45:01
| Show all posts
Use: bash let
Reply

Use magic Report

0

Threads

1

Posts

2

Credits

Newbie

Rank: 1

Credits
2

 China

Post time: 2020-7-28 16:15:01
| Show all posts
#!/bin/bash
cat a.ini | while read num
do
echo "$num"
#Design it yourself!
done
The above $num variable can get the value of each row in turn!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2020|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list