This extends Bash script interview Q&As – variables & arrays Q01 How will you concatenate strings in Bash? A01 In Bash, when variables or strings are written one after another, they automatically concatenate.
|
|
#!/bin/bash #global variable offline="&offline=true" #global variable with concatenation reqParams="oauth_nonce=$(uuidgen | sed 's/-//g')" # generate uuid & replace - with nothing reqParams="${reqParams}&oauth_signature_method=HMAC-SHA256" reqParams="${reqParams}&oauth_version=1.0" reqParams="${reqParams}${offline}" echo $reqParams |
Outputs:
|
|
oauth_nonce=E95431982C784E82B0FCAD0B8B2780B8&oauth_signature_method=HMAC-SHA256&oauth_version=1.0&offline=true |
Shell varaiable expansion modifiers Q02 What are Shell or Bash parameter or variable expansion...