Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [syntax]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
4 answers
73 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
421 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 ...
lamplet's user avatar
  • 35
3 votes
1 answer
207 views

Convention of parameter naming - undocumented options

GNU has long pushed for a combination of short options (-h) and long options (--help), which goes a long way to clearing up the syntactical mess of commands like tar and dd, with their legacy syntax ...
Popup's user avatar
  • 646
0 votes
1 answer
118 views

ShellCheck does not detect error? How to fix my snippet?

I likely have syntax errors in the following (POSIX) shell snippet: #!/bin/sh if tput setaf >/dev/null 2>&1; then tput_init_linux else tput_init_none; elif tput AF >/dev/null 2>&1;...
Vlastimil Burián's user avatar
-1 votes
1 answer
54 views

awk inside function causing errors

I'm trying to add the following to my .bashrc: cpu_info() { top -b -n1 | grep Cpu(s) | awk '{print $2 + $4}' } but bash is telling me: bash: .bashrc: line 131: syntax error near unexpected token `...
Mathew's user avatar
  • 243
-1 votes
1 answer
59 views

How to specify several alternative conditions (OR operator) for single case statement? (Or Alternatively, where is shell case syntax description?) [duplicate]

I want something like this: time="1m" case "$time" in *h*) *m*) *s*) echo "handling several cases for h, m, s tokens" ;; *) echo "...
Anton Samokat's user avatar
0 votes
1 answer
679 views

"Error in network definition: expected mapping (check indentation)" Syntax error in Netplan, I am trying to set up a static IP for my LAMP stack

Below are the configs for the yaml: file /etc/netplan/{filename}.yaml network: version: 2 renderer: networkd ethernets: eno1: dhcp4: false dhcp6: false addresses: [10.0....
Kyle Morton's user avatar
0 votes
0 answers
41 views

Better understanding accels/nemo file syntax to add keyboard shortcuts for custom Nemo scripts

I carefully followed the instructions to add keyboard shortcuts to custom Nemo scripts as explained in this Ask Ubuntu answer and this Stack Overflow answer. Although this technique works great to ...
End Antisemitic Hate's user avatar
4 votes
1 answer
91 views

lsof output file descriptor with asterisk not documented

When I run lsof I see the output java 1752736 user 9995u sock 0,8 0t0 1432559505 protocol: TCPv6 java 1752736 ...
lfmunoz's user avatar
  • 388
0 votes
2 answers
65 views

mv multiple files on Linux vs. on Mac

To move multiple files on Linux, one could use: mv -t DESTINATION file1 file2 Whereas on macOS it is mv file1 file2 DESTINATION Why is this difference? Is this a Bash vs. Zsh thing, or older vs. ...
jsx97's user avatar
  • 71
0 votes
1 answer
128 views

On simple filenames as commands versus arguments

I am reading Sobell's A Practical Guide to Linux Commands, Editors, and Shell Programming, 4e, and I am currently starting Chapter 5 on the basics of shells. On page 135 Sobell explains that From the ...
EE18's user avatar
  • 253
0 votes
1 answer
46 views

ansible-doc getting started?

Is there a vimtutor eqvivalent to ansible? I know I can read up on the syntax of a particular module using ansible-doc <module> - but what if I can't recall the module name? If I find myself ...
azzid's user avatar
  • 1,000
0 votes
0 answers
67 views

How shall I understand the synopsis of this command?

https://nixos.org/manual/nix/stable/command-ref/nix-shell.html Synopsis nix-shell [--arg name value] [--argstr name value] [{--attr | -A} attrPath] [--command cmd] [--run cmd] [--exclude regexp] [--...
Tim's user avatar
  • 103k
0 votes
0 answers
46 views

New error nessage "Can't use lokkit options with other options." from firewall-offline-cmd

A few months ago I wrote a script that helps configuring the firewall in SLES15. However when I ran the script today, I saw a new confusing error message like this: + firewall-offline-cmd --zone=...
U. Windl's user avatar
  • 1,493
1 vote
1 answer
58 views

Is there a way to make a comment after a "\" has been used to split a shell command onto differemt lines? [duplicate]

I am using arch and bash. Everything is up to date. I have this command which works just fine yad \ --timeout=2 \ --undecorated \ --posx=1200 --posy=633 \ --title=" " \ --window-icon='/home/$...
Kes's user avatar
  • 859
-2 votes
2 answers
63 views

Why is double bracket used to 'ensure' some commands, since it is not a logical check for "does it exist or not' (false/true)?

Recently I've been trying to figure out more and more shell syntax and logic behind some lines within scripts and I have the following question: What is the purpose of [[expression]] in the example ...
Andreyan Enchev Boyadzhiev's user avatar
4 votes
2 answers
138 views

How to make the (N) patterns of the zsh eatable by bash?

I am trying to develop a script which runs (and, ideally, does the same :-) ) in zsh and Bash. Problem is, that at a point, the zsh-specific part contains a pattern ending with (N). So: this_pattern*(...
peterh's user avatar
  • 9,848
0 votes
2 answers
579 views

Syntax error: "(" unexpected (expecting "fi") when using calculations

I am relatively new to shell, and I am getting a syntax error where I am still confused. #!/bin/dash ls="ls -l test" small=0 medium=0 large=0 for i in $(seq 11 9 56) do filename=$(echo ...
user avatar
0 votes
1 answer
76 views

Comments are causing errors after changing the value of "histchars" in zsh

Why, after using set histchars='?', is there an error that occurs every time I source ~/.zshrc? /home/user/.zshrc:1: bad pattern: # In other words, every # token within comments is causing some ...
user avatar
-3 votes
1 answer
78 views

What's "[@]" doing to variable in bash for loop

I was looking at how Gentoo's ebuilds are made and I found the following code: _VIM_PLUGIN_ALLOWED_DIRS=( after autoload colors compiler doc ftdetect ftplugin indent keymap macros plugin spell ...
Peter Petigru's user avatar
1 vote
1 answer
555 views

What does "*", "**", and "***" mean in Timeshift filters?

When excluding a folder, Timeshift generates a filter rule of this format: /home/nils/.cache/*** What do the three stars mean? And what do two or a single star mean?
Nils Lindemann's user avatar
-1 votes
1 answer
82 views

What is "in" in Bash?

I have encountered this in the syntax for case after calling help case and getting case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac. There was a question, whether "in" is a bash ...
Juandev's user avatar
  • 101
6 votes
3 answers
1k views

What does \ mean in bash and find?

I know that \ is an escape character, but when I write \ in bash, I have something like this: System-Product-Name:~$ \ > So bash waits for some instructions? When I use System-Product-Name:~$ \ &...
Marcus's user avatar
  • 251
-1 votes
1 answer
85 views

What are * and / in Bash?

I was trying to understand the following code ls -d */ and came to the explanation that */ "matches all of the subdirectories in the current directory". But that answer points out, what this ...
Juandev's user avatar
  • 101
1 vote
0 answers
396 views

How does the nftables set-syntax replacement for meters work exactly?

nftables nowadays recommends to use sets instead of meters when e.g. creating dynamic per-IP blacklists (example adapted from man pages v0.98: set blackhole { type ipv4_addr flags dynamic ...
reijerh's user avatar
  • 11
0 votes
2 answers
129 views

Dangers of executable file with '#' in name?

This might be a FAQ--happy to have the question closed if it's a dupe--but I'm not sure how to find it if so. I'd also be happy with an answer that simply told me how to find the relevant ...
Mars's user avatar
  • 103
0 votes
2 answers
131 views

what does syntax .= means in perl

I came across a Perl script which uses following .= syntax $key .= $descriptions[$i]; what does .= means here
Worker's user avatar
  • 37
0 votes
2 answers
1k views

How to search for a pattern with sed and replace another substring on that line

I need to find all lines in my data file that contain NO_ID and then replace the string "confirmed" by "to be confirmed". I tried this: sed '/NO_ID/, s/confirmed/to be confirmed/' ...
user167612's user avatar
  • 1,702
21 votes
2 answers
21k views

What does command eval "$(/opt/homebrew/bin/brew shellenv)" actually do?

Homebrew requires us to add eval $(/opt/homebrew/bin/brew shellenv) to ~/.zprofile. What does this actually evaluate to and what does this accomplish? I am a bit new to shell scripting. I know $var is ...
Osbridge's user avatar
  • 313
0 votes
1 answer
140 views

Confused about java -version [duplicate]

For every program/utility on Unix, I would type the name of the program followed by --version to check its version, like so program --version If I understand correctly, the double dash -- is used to ...
user avatar
1 vote
0 answers
29 views

Disk usage command not producing expected number of outputs [duplicate]

I want to run disk usage command (du) on both a parent directory (to find the total of all its contents), and then additionally on one of its subdirectories only. If I try to pass multiple paths into ...
teeeeee's user avatar
  • 157
-1 votes
2 answers
412 views

Test for a number in bash [duplicate]

Is this the correct way to test for a number, with double [[]] enclosing :digit: and single quotes surrounding the regex ? if [[ "$var" =~ '^[[:digit:]]+$' ]]; then
Vera's user avatar
  • 1
0 votes
1 answer
58 views

Compact form of a bash file extension test condition

I am testing whether arguments are not video files (.mp4, .mkv). Can I clean this so as to make it more compact test. if [[ ! "$1" == *.mp4 || ! "$1" == *.mkv ]]; then
Vera's user avatar
  • 1
0 votes
1 answer
1k views

Bash script error: syntax error near unexpected token `('

I want to run a command a number of times but with different arguments passed to it, so I wrote the following shell script to do that #!/bin/bash ...
coopdog218's user avatar
9 votes
1 answer
560 views

/RE/ vs. "RE" in awk

In awk, the first argument to the sub() and gsub() functions, the second argument to the match() function, and the optional third argument to split(), is an extended regular expression. Such an ...
Kusalananda's user avatar
  • 339k
1 vote
0 answers
81 views

How should alias in command substitution behave?

I tested a few scripts with different shells, and the results differ. # test 1 foo(){ echo $(al);} alias al='echo 123' foo # test 2 alias al='echo 123' foo(){ echo $(al);} alias al='echo abc' foo # ...
anonymous's user avatar
1 vote
1 answer
100 views

bash `if` block contents fail to execute due to syntax error on extended glob pattern in MacOS

Short Version: When extended glob is turned on inside a bash if block on my Mac, the entire block fails with a syntax error on any extend glob pattern contained in the block, even if it follows the ...
Arcticstar's user avatar
0 votes
2 answers
73 views

bash scripts - need help with syntax

I am reading the last line of 4 different files and grep for a certain string. Based on the string, I need to rename the source file. All 4 files have a different grep string and eventual target name. ...
Gail A. Jones's user avatar
0 votes
2 answers
97 views

Unable to uncomment just the cron by matching the string MYAPP

Below is my existing cron which i wish to enable crontab -l ####Cron to auto restart MYAPP ###*/15 * * * * ansible-playbook /web/playbooks/detectMYAPP/va_action.yml | tee -a /web/playbooks/...
Ashar's user avatar
  • 511
1 vote
2 answers
160 views

how to print PID along with the process dump

I wish to combine both the below commands: ps -ef| grep -v grep|grep java | awk ' {print "PID is:" $2}'; PID is:515 PID is:22145 PID is:32703 ps -ef| grep -v grep|grep java wladmin 515 ...
Ashar's user avatar
  • 511
1 vote
1 answer
327 views

test returns wrong value (but no errors) depending on the presence of spaces around the operator

If there are spaces around the operator, test returns the correct value of the expression. But if there are no spaces, it doesn't throw any syntax error and always return true. $ test "A" == ...
robertspierre's user avatar
13 votes
4 answers
1k views

Empty variable is treated as logical "true" with `$var && action` (shell parsing)

Consider a simple debugging style where $debug would be set either to true or false according to some command-line flag: $debug && echo "Something strange just happened" >&2 ...
Chris Davies's user avatar
0 votes
1 answer
168 views

Curious syntax error in script

I am creating a bash script to get cpu%, pps & incoming kbps #!/bin/bash INTERVAL="0.5" # update interval in seconds IFS="enp0s3" while true do # Read /proc/stat ...
ph3ro's user avatar
  • 378
0 votes
2 answers
80 views

Getting an error in the if condition

I am just checking whether the password contains a small and capital case letter, I am getting an error at line 19. myscript.sh: #!bin/sh read password conditionarr=(0 0) if [[ $password =~ [A-Z] ]] ...
bigstreet's user avatar
0 votes
0 answers
591 views

x unbound variable

I am trying to run that script here: #!/bin/bash set -o errexit # be strong with errors set -o nounset # be strong with unset vars PROG="${0##/}" # Scriptname USAGE="usage: $PROG ...
uek1967's user avatar
-2 votes
1 answer
256 views

Issue with grep pipeline in conditional

I'm a noob with bash scripting I'm trying to learn but I don't know how to fix this: ./elleviemme.sh: line 7: unexpected token `|', conditional binary operator expected ./elleviemme.sh: line 7: syntax ...
hflnmlie4594's user avatar
0 votes
1 answer
150 views

What does backticks do when in beginning of line in a bash script

I have noticed a weird behavior when a backtick is used in the beginning of line in bash scripts. example 1: echo "Test" `ls` Output: Test and ls is ignored. example 2: `test ':";`|)...
user7864052's user avatar
0 votes
1 answer
474 views

Syntax in conditional expression comparing with regex

I have tried to execute the code below on my Ubuntu machine, but it keeps saying "syntax error in conditional expression" and "syntax error near '0-9'" can you tell me why? while ! ...
user528910's user avatar
0 votes
1 answer
194 views

vconsole setup: unable to open the include file euro2

I formatted my Arch Linux and reinstalled for some reasons I wanted to start over After installation, a very strange error appeared. In the chrooted installation I created the file /etc/vconsole.conf ...
Devilas's user avatar
  • 77
0 votes
1 answer
1k views

alias in ash - limitation, syntax issue?

I'm running OpenWRT in a NAS (WD-MBL) and putting together a set of aliases to make maintenance easier via the command line. These work as expected: alias shutdown='sync && wait && ...
Groucho's user avatar
  • 31