Sample Header Ad - 728x90

Head function behaves differently inside an sh script and in terminal. Why?

0 votes
2 answers
105 views
I have variable x2 having 08PKj00000YdniC 09:59:04.53 (130409269)|SYSTEM_METHOD_EXIT||System.debug(ANY) ... many other lines from logs below I am trying to take the first line and discard everything else. When I execute echo $x2 | head -n 1 in terminal, I receive correct output 08PKj00000YdlM5 However, when I have an sh script and execute it from terminal like ./unwrap2.sh verbose I see strange result 08PKj00000YdniC 09:59:04.53 (130409269)|SYSTEM_METHOD_EXIT||System.debug(ANY) ... many other lines from logs below which looks like those lines are joined together even though I didn't expect this. What am I doing wrong inside a script and how can I fix this? Listing of unwrap2.sh shell script verbose=$1 # deploy data cloud Data Kit sf project deploy start -d dc # unwrap Data Kit components x=$(sf apex run -f scripts/unwrap.apex --json | jq '.result.logs' -r) x1=${x#*EXECUTION_STARTED} x2=${x1#*Result is \(success): } if [[ "$verbose" = "verbose" ]]; then echo "x2: $x2" fi x3=$(echo $x2 | head -n 1) if [[ "$verbose" = "verbose" ]]; then echo "x3: $x3" fi status=$(sf data query -q "select Id,Status FROM BackgroundOperation WHERE Id = '$x3'" --json | jq '.result.records.Status' -r) if [[ "$verbose" = "verbose" ]]; then echo "select Id,Status FROM BackgroundOperation WHERE Id = '$x3'" fi echo "Status: $status" while [[ "$status" != "Complete" ]]; do sleep 10 status=$(sf data query -q "select Id,Status FROM BackgroundOperation WHERE Id = '$x3'" --json | jq '.result.records.Status' -r) echo "Status: $status" done When I execute x3=$(echo $x2 | head -n 1) in terminal, it works fine.
Asked by Patlatus (123 rep)
Jan 13, 2025, 06:06 PM
Last activity: Jan 14, 2025, 01:19 PM