Questions tagged [syntax]
The syntax tag has no summary.
208 questions
0 votes
0 answers
12 views
Perl: Why is the position of `[:space:]` within a character class seemingly important? [migrated]
I'd like to use constants to build regular expressions. However, in this case I got an unexpected syntax error: me:~> cat foo.pl #!/usr/bin/perl use strict; use warnings; use constant CR_SAFE =&...
2 votes
3 answers
213 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
976 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
397 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
185 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
135 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
509 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
784 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
145 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
182 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
97 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
78 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
224 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 ...