Skip to content
Advertisement

Tag: variables

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

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

Advertisement