Questions tagged [syntax]
The syntax tag has no summary.
207 questions
2
votes
3
answers
181
views
bash syntax: what does '[@]+' mean? [duplicate]
I have a script that parses command line arguments.
The intro to the loop to iterate over the argument array looks like this:
for arg in ${args[@]+"${args[@]}"}; do
Can someone explain this ...
14
votes
2
answers
1k
views
Why do shell control statement have that syntax (semicolon/newline+then/do)
I of course realize the need to have something that separates the condition to the actual commands to be executed under the control statement, but why were it chosen to use both semicolon and a ...
10
votes
4
answers
947
views
With `#!/bin/sh`, what is the closest to `;;&` (`bash`'s fallthrough)?
Without ;;&, /bin/sh gives Syntax error: ")" unexpected (expecting ";;").
;;& triggers shellcheck's ^-- SC2127 (error): To use cases with ;;&, specify #!/usr/bin/env ...
2
votes
2
answers
390
views
Can I execute multiple case blocks if the pattern matches?
I want to know if there is another alternative in Bash to execute multiple blocks when the pattern matches.
I don’t want to use another command, if statements, or two or more separate case blocks or ...
2
votes
1
answer
170
views
Semicolon in conditional structures after the closing double bracket in a bash/zsh script?
Continuing Semicolon in conditional structures (which handles single brackets), what's the point of having a semicolon after the closing DOUBLE bracket ]]?
In my tests, running
#!/bin/zsh --
if [[ &...
0
votes
1
answer
122
views
Should my cat utility support multiple keys simultaneously?
So, i was given a task to implement simple version of cat utility. It should support some of GNU keys, for given text returns the same results as real cat utility and i was given this synopsis:
cat [...
2
votes
2
answers
486
views
Receiving " syntax error near unexpected token `then'" from remote Linux server with if, then, fi
I need help in determining why I get
syntax error near unexpected token `then'
from the following command:
for vm in {20..30} ; do ssh -q -o "StrictHostKeyChecking no" 192.168.210.${vm} &...
2
votes
2
answers
738
views
Merging values from 2 YAML files in bash
A bash command:
$(System.DefaultWorkingDirectory)/yq_linux_amd64 '. *= load("${{ parameters.HELM_CHART_PATH }}/values/DEV/${{ parameters.COMPONENT }}.yaml")' ${{ parameters.HELM_CHART_PATH }}...
5
votes
1
answer
123
views
Why can a list within a group be terminated with a space instead of a semicolon/newline as defined in the manual?
I am using the following version of the bash:
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
Man bash states the following for the "group" compound commnad:
{ list; }
list is ...
0
votes
4
answers
156
views
Details with bash's syntax checking and breaking over several lines
There are two cases in which I do not understand why bash behaves as it behaves regarding syntax checking and asking for a newline.
Case 1
bash can execute the line ( (ls) | cat), but depending on ...
2
votes
1
answer
90
views
Get PID of command in one line bash script [duplicate]
When trying to get the PID of a shell command, it is possible using a script file:
#!/bin/bash
ls -lha &
echo "$!"
However, it is not possible using only the terminal.
/bin/bash -c 'ls ...
-5
votes
1
answer
74
views
After wrote prompt $ sort [closed]
After I wrote prompt $ sort
display doesn't shown anything what the next step?
0
votes
1
answer
2k
views
bash 5.2.x + ternary operator: How can I use this combo when checking if my string variable is empty or not?
I have tried
#!/bin/bash
distro=""
myvar1=[[ -n "$distro" ]] && echo $distro || echo "debian"
myvar2=$((-n $distro ? $distro : "debian"))
these are ...
0
votes
5
answers
204
views
What is the difference between using code $variable and ${variable}2?
What is the difference between using code $variable and ${variable}2 ?
Example:
file ='GLOBAL_AR_COLLECTOR_COMMENTS20240614ALYSSAB.TXT'
prefix ='GLOBAL_AR_COLLECTOR_COMMENTS'
In my shell script code ...
3
votes
1
answer
476
views
What is the precedence of operators '=', '||'
In this command, if curl succeeds, then res will be set to the output of curl. It seems = has higher precedence than ||.
res=$(curl -s "http://example.com")||true
But || should have higher ...