You are not logged in.

#1 2014-06-29 11:04:09

Andy_Crowd
Member
From: 延雪平縣 Sweden
Registered: 2013-12-28
Posts: 119

export varibles & bc

This is the script that I am using with the find command to calculate a number of files:

if [ 'XX'"$RLASTFILENUMBER" != 'XX'  ]; then
export RLASTFILENUMBER="1"
fi
RLASTFILENUMBER=$(echo $RLASTFILENUMBER+1 | bc -l );

Gives errors like: (standard_in) 1: syntax error

I need it to make a limit of files in the folder before other actions.


Help to make Arora bug free!!
日不落 | Year 2081 | 笑傲江湖 | One more a really good book in my collection the Drystoll.

Offline

#2 2014-06-29 11:17:18

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: export varibles & bc

bash can do integers just fine on its own:

$ echo $((123+1))
124

Edit:

$ export RLASTFILENUMBER="1"
$ echo $(($RLASTFILENUMBER+1)) 
2

Last edited by karol (2014-06-29 11:18:24)

Offline

#3 2014-06-29 11:44:36

Andy_Crowd
Member
From: 延雪平縣 Sweden
Registered: 2013-12-28
Posts: 119

Re: export varibles & bc

I am exporting variables outside of the script but cannot read from within script.


Help to make Arora bug free!!
日不落 | Year 2081 | 笑傲江湖 | One more a really good book in my collection the Drystoll.

Offline

#4 2014-06-29 11:55:51

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: export varibles & bc

You said you were using this script with `find`, but you didn't describe how exactly. You need to describe the context better, what you're doing, what you're trying to do, etc.


This silver ladybug at line 28...

Offline

#5 2014-06-29 11:56:52

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: export varibles & bc

I'm not sure what's the correct way of doing this, but

#!/bin/bash

foo="1"

echo $(($foo+1))

works.

Offline

#6 2014-06-29 12:13:03

Andy_Crowd
Member
From: 延雪平縣 Sweden
Registered: 2013-12-28
Posts: 119

Re: export varibles & bc

I am using like

$ export DDD="1"
#!/bin/bash
export DDD=$(echo $(($DDD+1)))
echo $DDD

I want it to remmember the variable value outside of the script. Because I need to run this script many times and cannot keep everything inside.


Help to make Arora bug free!!
日不落 | Year 2081 | 笑傲江湖 | One more a really good book in my collection the Drystoll.

Offline

#7 2014-06-29 12:16:27

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: export varibles & bc

Can you post the rest of the script, the 'find' part?
You can make it read a value from a file, if needed.

Offline

#8 2014-06-29 12:53:07

Andy_Crowd
Member
From: 延雪平縣 Sweden
Registered: 2013-12-28
Posts: 119

Re: export varibles & bc

I am using something like

find * -type f -name * -exec myscript.sh \;

each time it runs the script a new value should be stored and calculated.
It will take more time if a file will be created for variables. I am making script for finding files by type and sort them by folders. I have more then 50 000 files and I want to automate searching and sorting out of images and other files by a type. In a preview post you can see the more important part of the script, but I solved it, only this part with calculation left.

Last edited by Andy_Crowd (2014-06-29 13:01:15)


Help to make Arora bug free!!
日不落 | Year 2081 | 笑傲江湖 | One more a really good book in my collection the Drystoll.

Offline

#9 2014-06-29 13:02:22

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: export varibles & bc

'find -type f -exec myscript.sh \;' should work too.

What does myscript.sh do?

Offline

#10 2014-06-29 13:08:32

Andy_Crowd
Member
From: 延雪平縣 Sweden
Registered: 2013-12-28
Posts: 119

Re: export varibles & bc

you can read this post my solved post


Help to make Arora bug free!!
日不落 | Year 2081 | 笑傲江湖 | One more a really good book in my collection the Drystoll.

Offline

Board footer

Powered by FluxBB