Questions tagged [syntax]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
2answers
66 views

^ syntax error in awk when called via ssh

I'm running filesystem usage command to detect /var filesystem usage beyond 80% from one host to multiple remote hosts. My command runs fine (df -h /var | awk '$1 > 80'), but with ssh it gives me ...
0
votes
2answers
136 views

What is precisely the role of the '&' character in a bash/shell redirection? [duplicate]

So as I'm writing my own shell for school, I have to implement redirections. I've looked at the GNU Bash manual, and a fair amount of tutorials, but I'm still having troubles understanding what ...
0
votes
1answer
23 views

what `foo=bar programname` means [duplicate]

While developing a React app, I needed to use some environment variables. The way to do it is by using this syntax: REACT_APP_NOT_SECRET_CODE=abcdef npm start see reference My first question is: ...
2
votes
1answer
31 views

Temporary display full name of argument instead of short name/abbrev

After an command, where the user should give an output location with -o, I wondered if there is an (standard) command that temporary displays the full name of the given argument, like the -o, that ...
1
vote
1answer
38 views

Problem with auto-completion on VPS

I just set up a VPS with hostinger.com. The OS is Ubuntu 18.04. I created a user account, mike. I quickly realised that auto-completion wasn't apparently installed so looked up how you do this. For ...
2
votes
1answer
50 views

Consolidate several GraphicsMagick (ImageMagick) commands into one

There are many times I get single page PDFs that I want to convert to JPEGs and crop the excess whitespace off of. Here is the current set of commands I have which accomplishes what I want: gm ...
0
votes
1answer
71 views

bash script single quote and backslash creation

I'm trying to write a bash script for a snapshot backup with rsync to a server. The command I want to invoke is rsync -aPh -e ssh --rsync-path='sudo rsync' --link-dest=../last /home/username/files ...
0
votes
1answer
89 views

iptables command is not accepted in parrot OS

I created my own chain called test. I want to insert a new rule in the chain that drops all packets to an IP address at a specified port. sudo iptables -I test -j DROP -d 130.x.y.z -dport 24 The ...
4
votes
3answers
2k views

I am getting “syntax error near unexpected token `'$#''” in a simple Bash script

I'm using Debian 10 (Buster) and am getting an error in a simple Bash script. All it does is check to see if one parameter is passed in, and if it's a file, just echo out the file: #!/usr/bin/bash if ...
1
vote
1answer
57 views

Why should I set the source device with < > when using pv?

I have a question out of curiosity ;-) I find that I could accomplish cloning a disk with the command pv instead of dd too. For that I used what I found in the internet pv < /dev/sda1 > /dev/...
0
votes
0answers
19 views

Why a result from history command doesn't behave in a bash function? [duplicate]

I started learning bash script recently, and I got stuck with this situation. I want to use a result from history command for some purpose. First, I tried to extract the 2nd column (command name) ...
11
votes
1answer
669 views

Why can't you reverse the order of the input redirection operator for while loops?

In Bash you can move input redirection operators to the front of a command: cat <<< "hello" # equivalent to <<< "hello" cat Why are you unable to do the same for while loops? ...
-2
votes
2answers
66 views

Help with indexing a list of values

I need to track a huge log and more exactly a column. In this column I have some integer values in a rage between 103 and 17431. Example of original file 402 402 402 667 942 342 990 402 For every ...
-1
votes
2answers
50 views

Defining several variables at once (copy-paste-execute in shell)

I have a list of variables I copy-paste one by one from a file to my shell and hit Enter to execute. For example: var1="myvar1" var2="myvar2" Because in practice there are more variables, instead ...
-3
votes
1answer
121 views

Time and again I forget the meaning of a single hyphen in the end of some utility commands [duplicate]

Time and again I come across old codes and recognize a single hyphen in the command's end: mysqldump -u root -p --all-databases | zip "$drt/db-$date.zip" - or wget ${target_url} -O - | tar -xzv --...
0
votes
1answer
89 views

Convert Date string in timestamp

I can't find the right syntax to convert a string date in epoch timestamp. The script is: date -d '2012-03-02 22:00 EDT' +%s DATEJ=`echo -n \'2012-03-02 22:00\'` echo $DATEJ date -d $DATEJ EDT +%s ...
-2
votes
1answer
100 views

Is there a reason to use \+ or \- in date arguments?

I use date \+%F\-%T to show date and time in this format: 2019-08-15-21:34:58. From man date: %F full date; same as %Y-%m-%d %T time; same as %H:%M:%S I recognized no explanation for \+ or \...
25
votes
3answers
4k views

What is the meaning of [[:space:]] in bash?

I just came across a bash script. What does [[:space:]] mean in a bash script? Why the double colon?
0
votes
2answers
123 views

Set shell variable then invoke subprocess fails

I was playing with getopts, which has a shell variable OPTERR that influences its behavior. I wanted to change the value of OPTERR and invoke getopts on the same line, to affect the behavior of ...
2
votes
1answer
46 views

What is the difference between vertical pipe and juxtaposition in JQ?

My program returns JSON into stdout and it is an object with operations field, which contains a list of operations. Each operation contains fields including id fields, for example: { "operations":...
10
votes
2answers
551 views

Why does a brace command group need spaces after the opening brace in POSIX Shell Grammar?

TL;DR: Why does POSIX brace group need spaces after { reserved word but subshell doesn't after reserved word (? POSIX shell grammar defines brace group and subshell as follows brace_group : ...
0
votes
1answer
66 views

Can anyone help me figure out what this “find” command with curly braces is saying? [duplicate]

I found some old notes where someone suggest I run the following command to set some file permissions: find /perl/lib/ -type f -exec chmod o+r \{\} \; Would you happen to know what the \{\} part of ...
0
votes
1answer
67 views

rsync with filter to include only certain file types for specific directory trees

my rsync command looks like this: rsync --update -rav --filter="merge $HOME/mergefilter.txt" ~/ (remote_destination):~/ My mergefilter.txt file looks like this: + /directory_1/*** + /directory_2/***...
0
votes
1answer
39 views

Evaluate command based on variable at bash [closed]

I am writing a small script that would choose random file for me from the directory and execute command with this chosen filename as a parameter. It is about choosing random .ovpn file and run sudo ...
0
votes
0answers
47 views

Why does single quotes around arguments fail to prevent “syntax error near unexpected token '('”? [duplicate]

I read that surrounding command line arguments with single quotes is necessary when the command line argument is a string that contains parentheses. However using single quotes around the following ...
0
votes
1answer
18 views

Is it possible to schedule an anacron single line command execution instead of sourcing a file?

Everywhere on the internet, in articles or tutorials (in the searching of "schedule an anacron command"), I find a format such as the following: @daily 15 rsync.daily /bin/bash /home/steven/...
0
votes
2answers
702 views

syntax error near unexpected token 'elif'

I get the error on the 7th line. Any ideas? I checked for spaces and there are none. #!/bin/bash if test $# -eq 0 then echo "No arguments" elif test $# -eq 1 echo "$1" elif test $# -eq 2 ...
0
votes
2answers
85 views

Changes to bash shell script language? [closed]

i wrote a multipart script that calls rsync a few years ago and it has always worked. After a year of no use and alot of debian apt-get updates, now the script stopped working. Main2Network1.sh ...
-1
votes
1answer
123 views

Why would calling cd (builtin) from cd (shell function) without “command” cause an endless loop?

I once read in a Bash book by O'Reilly the following (my summary): command and enable cd () { echo "Improved CD !" # Improvement one; command cd # Improvement two; # Do cool ...
2
votes
0answers
86 views

How to maintain a list of names for the Hunspell spell checker?

Hunspell should help the user to write names properly. The names should be defined in the home directory of the user, so that every user can define his or her own list of important names. If a user ...
0
votes
1answer
608 views

How to run Ansible playbooks only if there are no problems in the playbook?

I have learned of the command ansible-playbook example.yml --check which can tell me if something in my playbook is problematic (as far as Ansible can recognize). I think I should combine this ...
0
votes
1answer
22 views

What are the basic files (dirs and regular file) in Ansible-Galaxy roles? [closed]

I have an Ansible playbook for establishing LAMP environments on remote machines. Part of this playbook deals with installing Composer: - name: Install Composer get_url: url: https://...
2
votes
1answer
277 views

Is it a best practice to use Ansible-Galaxy roles in playbooks instead ansible-modules in playbooks? [closed]

I have an Ansible playbook for establishing LAMP environments on remote machines. Part of this playbook deals with installing Composer: - name: Install Composer get_url: url: https://...
6
votes
2answers
1k views

How to write regexp literal in match expression?

This question is about the proper way to write regular expression literals in a match expression under bash. In zsh, the match below succeeds, as I expected: % [[ ' 123 ' =~ '^ [0-9]+ $' ]]; echo $? ...
1
vote
0answers
35 views

Sed command writes the expression in outer ifmodule

my config file has this <IfModule mod_dir.c> DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm </IfModule> I want to change "index.php" to "index.temp" I ...
-8
votes
5answers
2k views

What is masking a mode?

I understand that in GNU/Linux, file permissions are also called a file's mode and that the term mask can mean at least these different meanings: The umask shell builtin (the usual meaning). The ...
4
votes
1answer
211 views

Have remind send out notifications some days in advance

I have been trying to use the Unix program remind, and so far I enjoy the flexibility. I have set up this command to warn me of any upcoming reminders: ~$ remind -z -k'notify-send "Reminder" "%s"' ....
2
votes
2answers
274 views

How can I use “source-highlight” with “git show”?

Using source-highlight in conjunction with less works really well, but I'm struggling to see how I can use it with git show because there's no file extension to clue source-highlight about the ...
3
votes
1answer
125 views

Using a bash array in an awk and also quoted variable: conflicting syntax issue

I have a script the aim of which is: For a list of files, obtain a specific number for each file (this is sequencing data, to be specific) and store these into array1 Using array1, find the smallest ...
17
votes
1answer
3k views

Bash script function names containing double colon '::'

I came across a Bash script today that has function names with double colons :: in them, e.g., file::write() and file::read(). I've never seen this syntax before in a Bash script, and when I invoked ...
1
vote
1answer
164 views

Dash Slash Meaning vs just Slash -/var vs /var [duplicate]

Working with Centos 7 In the rsyslog.conf file there are some rules that place logs in directories that start with a -/ (Dash slash) before stating which directory to place the logs, while others ...
8
votes
4answers
2k views

back ticks vs double quotes

I've been wondering this for a long time but haven't figured out how to look it up - is this: x=`command -v r2g` the same as this: x="$(command -v r2g)" or is it the same as this: x=$(command -...
54
votes
3answers
11k views

Is $() a subshell?

I understand the subshell syntax to be (<commands...>), is $() just a subshell that you can retrieve variable values from? Note: This applies to bash 4.4 based on different wording in their ...
2
votes
0answers
91 views

What are the contexts where Bash doesn't perform word splitting and globbing?

Bash doesn't perform word splitting in globbing in these cases: LHS or RHS of an assignment, except for indexed arrays var=$value # simple variable declare -A hash key=...
-1
votes
2answers
319 views

Why not seeing shell globs as a “dialect” of regex? [duplicate]

I often confuse Bash 3.x shell globs: ? # Match any single character. * # Match any string of characters (up until the asterisk). [set] # Match any character in set (but not the entire set ...
0
votes
1answer
20 views

lp -d lp1 -h myfile has two options and one argument or 2 options and 2 arguments?

In "Learning the Bash Shell" by O'reilly (third edition), it is written in page 7: lp -d lp1 -h myfile has two options and one argument. How come? I see what I reckon as two options, each one with ...
0
votes
1answer
354 views

What does the asterisk (*) mean in lsof output?

I set my TCP server to localhost 127.0.0.1, but instead of seeing 127.0.0.1 in the host portion of the lsof output, I see an asterisk. After running lsof -i... my_process 66666 root 5u IPv4 0xffff......
-1
votes
5answers
291 views

Are if-fi segments necessary when iterating on a pushd-popd directory list?

I use the following code which is part of this script that I use to update my WordPress websites: #!/bin/bash drt="/var/www/html" for dir in ${drt}/*/; do if pushd "$dir"; then wp plugin ...
1
vote
2answers
362 views

AWK usage for simulatenous inline division and taking absolute value

I have a data file of this format (top row is for reference): E T N D S s R k 0.45847 300.0000 9....
1
vote
1answer
133 views

Hyphen (-) ignored in the end of a piped command nested inside a function?

I use Ubuntu 16.04 (xenial) with Bash 4.3.48(1). Based on the answer of Stephen Kitt in this session, I tried run the following command as part of a function named imb(): mysqldump -u root -p --all-...