In bash, how to store stdin and stdout file handle in variable?

I have the following bash script: STDIN=’&0′ if some-condition; then STDIN=some-filename fi run-command <${STDIN} But that errors with &0: No such file or directory. Similarly for STDOUT. I’ve tried using eval but haven’t gotten that to work, either. What needs to be done to get this to work? >Solution : STDIN=’/dev/stdin’ # Default to stdin… Read More In bash, how to store stdin and stdout file handle in variable?

compare two strings in bash if statement

i am trying to make an if statement in a bash script: file_exists=$(psql -h $DB_SERVER -U $DB_USER -d $DB_DATABASE -t -c "SELECT source_file FROM $DB_SCHEMA.cj_metadata WHERE source_file LIKE ‘%$base%’;" | grep "$base") echo "FILE EXISTS: $file_exists $base.jsonl" # Check if the file exists if [[ "$file_exists" == "$base.jsonl" ]]; then echo "File $base.jsonl is already… Read More compare two strings in bash if statement

Replace string with link in bash

I want to replace a sentence in a file this: from [Report 1](**Please put link here**)" [Report 2](**Please put link here**) to: [Report 1](https://stackoverflow.com/09004cffcbee784a?docno=/link1)" [Report 2](https://stackoverflow.com/09004cffcbee784a?docno=/link2) So I tried with but it does not seem to make the replacement sed -i ‘s#[Report 1](\*\*Please put link here\*\*)#(https://stackoverflow.com/09004cffcbee784a?docno=/link1)#g’ file.md >Solution : Square brackets are special in sed… Read More Replace string with link in bash

cd into directory using multiple variables from back script

This script appears useless I know but I’m testing for a final variant. When I call cd using multiple variables. Nothing happens. However, when I echo ${this}${that} it produces the proper text. What do I need to do to drop into the directory correctly from a bash script? #!/bin/bash this=/path/to that=/final/directory echo ${this}${that} cd ${this}${that}… Read More cd into directory using multiple variables from back script

How to use sed or awk in script to print numbers from line?

I have this line "sha": "60dede389922f81a64ddb5f30ab6fe8a73deb643", How to use sed or awk to print only 60dede389922f81a64ddb5f30ab6fe8a73deb643 ? I have use awk ‘/sha/{print $1, $NF}’ | sed ‘s/[^0-9]\{4\}//g’ But I have got wrong vaule 60389922f81a64ddb5f30ab6fe8a73deb643", >Solution : What I would do: awk -F’"’ ‘/^"sha"/{print $4}’ file But I prefer this grep version: grep -oP ‘^"sha":\s+"\K[[:xdigit:]]+’ file… Read More How to use sed or awk in script to print numbers from line?

Bash: Loop over an associative array with list as values

I am a newbie with Bash. I am trying to loop over the following array – declare -A X=( [‘s1’]="firstname" [‘s1’] "secondname" [‘s2’]="surname" [‘s3’]="other" ) for arg in "${!X[@]}"; do echo "${arg}, ${X[${arg}]}" done However, I realized that since the key s1 is repeated, only one of the values will be printed. Therefore I did… Read More Bash: Loop over an associative array with list as values