Skip to content
Advertisement

Error concatenating var in bash script

I have a bash script that searchs for password for unrar files. I would like to concatenate result and at the end of the script notify result of execution, but I don´t know why final_result var outputs “INIT-END”.

Why does not concatenate in search_pass_and_unrar function?

JavaScript

Thanks a lot, best regards.

Advertisement

Answer

Problem is here:

JavaScript

Due to pipeline used here your script is forking another subshell and calling unrar_files in a subshell. Due to this subshell creation all the changes made to final_result are not visible in current shell.

You can fix it by using process substitution like this:

JavaScript

Note use of -print0 to make sure we can process files with special characters as well.

Similarly inside unrar_files you need to this:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement