shenwei356 / rush

A cross-platform command-line tool for executing jobs in parallel
https://github.com/shenwei356/rush
MIT License
846 stars 63 forks source link

Bash conditionals inside #31

Closed bsysop closed 4 years ago

bsysop commented 4 years ago

Hi Shen, first at all, thank you very much for rush, im a gnu/parallel heavy user, and now im migrating to rush, running away form perl =]

I normally execute something like this

for PATH in $(<file.txt); do([[ -d ./$PATH ]] && echo $PATH); done

or

cat file.txt | parallel '[[ -d ./{} ]] && echo {}'

but in rush i go the next.

14:24:23.705 [ERRO] wait cmd #10: [[ ! -d ./example1 ]] && echo 1: exit status 1

with command

rush --jobs 1 '[[ ! -d ./{} ]] && echo {}'

Do you mind what could happens here?

Thank you very much!.

shenwei356 commented 4 years ago

It's weird and I don't have a clue, but you can use alternate if then fi solution with 3 more words now.

@bburgin may know, Brian contributes lots of features of rush.

bsysop commented 4 years ago

If you need something i do, please tell me.

bburgin commented 4 years ago

On Windows, I was able to get this to work: bash.exe -c 'echo -n "test1 test2" | rush -D " " bash.exe test.sh {}'

where test.sh contains: [[ ! -d ./$1 ]] && echo $1

bsysop commented 4 years ago

Got it, you means to write a script to run inside, understand

Some other tools have the next syntax:

TOOL_CMD -- sh -c 'something_to_exec {}'

Then you choose "SH" to interpret your command inside, then you can do any bash script syntax there.

Gnu/parallel does it simply, you dont need call sh or bash to execute bash script functions inside.

shenwei356 commented 4 years ago

rush inside calls 'sh -c "xxxxx" ', script is not necessary, if else works , but && ([[ ! -d ./{} ]] && echo {} ) failed, weird.

bsysop commented 4 years ago

Oh guys, i think i got what happens here, first at all i made a mistake in my first post in that issue, you can see in for command and in gnu/parallel i used [[ -d {} ]], and in rush i used [[ ! -d {} ]], the negative data...

But anyways you will understand what make me think have something wrong:

In gnu-parallel/for loop/others when i run [[ ! -d ./{} ]] && echo {} If dont exist the folder, that just be ignored, but in rush he gives a error.

rush --jobs 1 '[[ -d ./{} ]] && echo {}' works perfect

but false conditional fails

rush --jobs 1 '[[ ! -d ./{} ]] && echo {}' give error in stderr if folder dont exists.

Would be more proper to just ignore in case folder dont exist?

bburgin commented 4 years ago

What about: if [ ! -d ./{} ]; then echo {}; else echo 0; fi

bsysop commented 4 years ago

Hi @bburgin that works! Just not so useful as [[ something ]] && command

I think we can close this issue, looks more a rush "how to" than an error!

Thank you very much for your time.