Questions tagged [syntax]
The syntax tag has no usage guidance.
188
questions
1
vote
1
answer
47
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/$...
-2
votes
2
answers
54
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 ...
4
votes
2
answers
80
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*(...
0
votes
2
answers
159
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 ...
0
votes
1
answer
55
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 ...
-3
votes
1
answer
75
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 ...
0
votes
1
answer
208
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?
-1
votes
1
answer
46
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 ...
5
votes
3
answers
937
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:~$ \
&...
-1
votes
1
answer
60
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 ...
0
votes
0
answers
124
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
...
0
votes
2
answers
115
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 ...
0
votes
2
answers
108
views
what does syntax .= means in perl
I came across a Perl script which uses following .= syntax
$key .= $descriptions[$i];
what does .= means here
0
votes
2
answers
412
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/' ...
12
votes
2
answers
8k
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 ...
0
votes
1
answer
53
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 ...
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 ...
0
votes
0
answers
191
views
converting /etc/network/interfaces network config syntax to netplan
Trying to do some network configuration after upgrading to Ubuntu 22.04 (from 16.04) and am a bit confused with the syntax.. I'm a total noob! I've googled a lot but still not able to find what I'm ...
-1
votes
2
answers
159
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
0
votes
1
answer
34
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
0
votes
1
answer
683
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 ...
9
votes
1
answer
491
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 ...
0
votes
0
answers
27
views
Difference between command1; command2 and (command1; command2) [duplicate]
I know that command 1; command 2 means that: run command1 first, then run command2. But, what if the command has parenthesis around it ? like (command1; command2). What is the difference between these ...
1
vote
0
answers
50
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
# ...
1
vote
1
answer
72
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 ...
0
votes
2
answers
69
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.
...
0
votes
0
answers
29
views
Correct if statement syntax in shell script [duplicate]
Following codes
echo 'input text : '
read -a names
for((i=0;i<${#names[@]};i++))
do
name="${names[$i]}"
echo "given input is"
echo ${name}
test="test1"
...
0
votes
2
answers
74
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/...
1
vote
2
answers
108
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 ...
1
vote
1
answer
180
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" == ...
0
votes
0
answers
87
views
How to grep from a variable
I'm trying to grep from a variable,
I'm not sure why the logic isn't working correctly. I would like to enter the loop when the counter is 1 and then check the sta_status variable if the expression ...
0
votes
0
answers
17
views
How is the syntax with a loader before the command desribed in bash and other similar shells? [duplicate]
While reading this I saw this kind of strange command
$ /lib64/ld-linux-x86-64.so.2 ./app
$ LD_DEBUG=all /lib64/ld-linux-x86-64.so.2 ./app
Unexpectedly they really works
What are these? The man pages ...
13
votes
4
answers
985
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
...
0
votes
1
answer
63
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 ...
0
votes
2
answers
70
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] ]]
...
0
votes
0
answers
512
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 ...
-2
votes
1
answer
183
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 ...
0
votes
1
answer
119
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 ':";`|)...
0
votes
1
answer
303
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 ! ...
0
votes
1
answer
158
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 ...
0
votes
1
answer
886
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 && ...
3
votes
1
answer
264
views
tmux configuration: command output substitution doesn't
I am trying to make parts of my .tmux.conf file conditional depending on the kind of system I'm on. For a start, I want one part to only be processed on MacOS.
The man page says that I can use the #(...
-6
votes
1
answer
69
views
Is there an example for a shell or computing accessibility culture aspiring a shell with more special characters and if so what is it? [closed]
I was always a bit frustrated from the lack of characters in modern computer systems such as, from what I know:
A global template literal character for which the closest character today is a backtick ...
0
votes
1
answer
881
views
How do I append the outputs of the echo -e command into two separate files, simultaneously?
First, Thank you for your time and effort to help me with this situation. Now, without further ado, my issue.
I am a student in Cybersecurity and I am attempting to make bash script to enumerate my ...
-1
votes
2
answers
58
views
averaging a column of a file
I have a CSV file (with time-stamped data), and I have a script
that will break each month of the year into a separate file.
The script will take that month and average out the data to a single value....
-2
votes
2
answers
157
views
bash error syntax random number [closed]
My assignement is to show a random number (od -vAn -N4 -tu4 < /dev/urandom) between two numbers in read. I don't understand why there are syntax error when I check the min value exception and with ...
0
votes
1
answer
154
views
linux shell script with if and shopt [duplicate]
I've written the following shell script:
#!/bin/bash
...
#delete downloaded file
if [ "$param" == "delete" ]; then
shopt -s extglob
cd $DataPersistent/download/
rm -f ...
-2
votes
1
answer
283
views
In the synopsis of a man page, what do ellipses following brackets mean? [duplicate]
The following image is from the POSIX documentation's section on Utility Argument Syntax.
My question is this: Are the two argument forms in the image more or less identical, besides one using the ...
0
votes
0
answers
272
views
tcpdump to monitor snmp from subnet causing syntax error
I'm trying to monitor SNMP from 2 hosts on the same subnet; 10.52.17.31 and 10.52.17.32. They are on the only machines on that subnet.
Using the following commands I receive a syntax error:
tcpdump -...
1
vote
1
answer
444
views
Hyphen in bash function names [duplicate]
Am writing bash functions. It looks like function names can include hyphen: -.
Thus indus-headrc () and indus-tailrc (). Had thought that only underscore is allowed.