I’m learning to script in Bash. I have an CSV file, which contains next lines: Need to create arrays from this, where first entry is array name, eg. Here is my script: When I try with csv file, containing only two first string (numbers and colors), code works well. And if i try to with number, colors, custom-1, custom-2, there
Tag: variables
Declaring variables with indirect reference with a prefix
I have my parameters stored in a file and calling them with a prefix which i get it has input. now, i am getting the input and prefixing it and storing as a new variable and then pointing my new variable indirectly to my actual variable to use in my script. Is there a way to directly mention the indirect
Indirect expansion returns variable name instead of value
I am trying to set up some variables using indirect expansion. According to the documentation I’ve read, the set up should be simple: I should be getting “12345”. Instead, the output is “varname”. If I remove the exclamation point, I end up with “qa_ci”, not “12345” This should be a relatively simple solution, so I’m not sure what I’m missing,
Assigning variable to a variable inside if statement
I am trying to assign a variable from a prompt input choice with no luck. If the user inputs 1, I want target_db_name = “database2”. My code: I have tried creating another if statement with no luck. Answer if $target_db = “1” then won’t work, because what follows if must be a command, not a test expression. Now, the most
Using variables as the input to command
I’ve scoured various message boards to understand why I can’t use a variable as input to a command in certain scenarios. Is it a STDIN issue/limitation? Why does using echo and here strings fix the problem? For example, As you can see I get the error… ‘File name too long’ Now, I am able to get this to work by
Check if any file in a directory contains words in a constant file
i have a directory with n textfiles. Now, i want to check, if any of these files contains one (or more) words of a constant file. These files are all dictionarys with a different amount of words. The constant file is a password list, where i want to check these words. The amount of correct hits should be saved in
How to echo a dynamic variable’s content in shell script
How to echo a dynamic variable’s content in shell script ? Current output: Desired output: Answer Use eval:
While loop not equal command not found
I am trying to perform a simple while loop comparing a variable to a string. It fails to load with the error on this line. Error states [: missing `]’ and : command not found. My while loop looks like; Answer There are a couple of errors: See that variable declaration do need to be like var=value. Otherwise, bash would
How to base64 encode image in linux bash / shell
I’m trying to base64 encode an image in a shell script and put it into variable: I’ve also tried something like this: but still with no success. I want to do something like this: I found this http://www.zzzxo.com/q/answers-bash-base64-encode-script-not-encoding-right-12290484.html but still have had no success. Answer You need to use cat to get the contents of the file named ‘DSC_0251.JPG’, rather
linux shell title case
I am wrinting a shell script and have a variable like this: something-that-is-hyphenated. I need to use it in various points in the script as: something-that-is-hyphenated, somethingthatishyphenated, SomethingThatIsHyphenated I have managed to change it to somethingthatishyphenated by stripping out – using sed “s/-//g”. I am sure there is a simpler way, and also, need to know how to get the