Questions tagged [syntax]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2
votes
2answers
2k views

Syntax error near unexpected token 'else'

I'm trying to create a script that will remove certain parts of a txt file full of status info and other various text. I can't end the main if statement. Also I'm trying to get it to delete the ...
1
vote
0answers
34 views

Exclude subdirectory from zip archive — explain syntax please

I want to zip a folder recursively, but exclude certain directories (temp/.hidden in the example below). I want the zip file to have a top level folder which would be temp in the example below, hence ...
-3
votes
2answers
445 views

Using an shell glob (wildcard (*)) after a double quoted variable expansion

I read that it is a best practice to double quote all of your variable expansions in Bash. I also read that one cannot use a shell glob (wildcard(*)) right after a double quoted variable expansion. ...
1
vote
1answer
199 views

Basic usage of /etc/cron/ (d): correct pattern for /etc/cron (daily/weekly/monthly)

I use Ubuntu 16.04 with Bash and I've created this extensionless, shebangless file /etc/cron.daily/cron_daily: for dir in "$drt"/*/; do if pushd "$dir"; then wp plugin update --all --allow-root wp ...
8
votes
2answers
2k views

How to export a large list of variables in Bash? [duplicate]

I use Bash 4.3.48(1) and I have a .sh file containing about 20 variables right under the shebang. The file contains only variables. This is the pattern: x="1" y="2" ... I need to export all these ...
1
vote
1answer
61 views

How to use one path in heredocument

I wrote this here-document to source a few scripts under the path ~/own_scripts/ but I wrote it in a way that causes duplication of this path: source <<-EOF ~/own_scripts/1.sh ~/own_scripts/...
2
votes
2answers
362 views

From multiline heredocument to a uniline herestring, with line breaks

I have this multilinie heredocument which I desire to translate into a uniline herestring: cat <<-"PHPCONF" > /etc/php/*/zz_overrides.ini [PHP] post_max_size = 200M upload_max_filesize ...
0
votes
4answers
176 views

What's the pattern in terminal commands?

Just starting to dive into the terminal thanks to the fun Raspberry Pi. I have one thing in particular that still has me scratching my head: I'm noticing the different daemons / services / processes /...
1
vote
2answers
66 views

How does '-' work in bash redirection?

I have seen this explained somewhere before but can't find a reference now. An example usage from docker getting started guide for Ubuntu: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | ...
14
votes
2answers
64k views

How to pass parameters to function in a bash script?

I'd like to write a function that I can call from a script with many different variables. For some reasons I'm having a lot of trouble doing this. Examples I've read always just use a global variable ...
3
votes
1answer
248 views

Breaking long lines with comparison operators in a shell script

in my bash code sometimes I use long parameters in Comparison Operators to test the "OR" as the following: if [[ $production_check_linux_disks_quantity == false ]] || [[ $...
1
vote
2answers
231 views

Syntax for `repeat` with a semicolon in the command string?

I'm keeping an eye on a process in FreeBSD using a script which outputs the current status of the job. Using the csh builtin command repeat, I'd like to run the script every 2 seconds, so naively I'd ...
5
votes
2answers
764 views

Why is `source ~/.bash_aliases` exiting with syntax error?

What is the syntax error in this file? I can't spot it. set-k8s-azure() { export KUBECONFIG=~/.kube/config.azure-1 } set-k8s-minikube() { export KUBECONFIG=~/.kube/config.minikube } minikube() {...
-2
votes
1answer
2k views

What does $a and -e mean in sed? [closed]

[desktop ~]$ cat sa sanmesh shammas sujil givin nepo bijal [desktop ~]$ sed -i -e '1i Header' -e '$a Trailor' sa [desktop ~]$ cat sa Header sanmesh shammas sujil givin nepo bijal Trailor
0
votes
0answers
149 views

HP:the arguments in killall beyond `man killall`

In the tutorial here : /usr/bin/killall -HUP rsyslogd For the command : /usr/bin/killall -HUP rsyslogd In my os,the synopsis info in man killall SYNOPSIS killall [-Z, --context pattern] [-...
0
votes
1answer
653 views

Commands Grouping

I understand the ampersand & at the end of a command sequence executes it on the background (in "parallel"), the semicolon ; allows for sequential (in "series"), and the parenthesis allows command ...
1
vote
1answer
94 views

Is it a best practice to wrap paths in quotation marks?

Consider the following code: for domain; do cat << EOF > "/etc/nginx/sites-available/${domain}.conf" My \domain is ${domain}. EOF done Note that the path /etc/nginx/sites-...
35
votes
6answers
6k views

Is ~/Mary a relative path? [duplicate]

Let's suppose Mary is a directory. Is the following path ~/Mary relative?
1
vote
1answer
8k views

syntax error near unexpected token `do

I have a "syntax error near unexpected token `do" error, using a for loop in a .sh. Here is the code : #!/bin/sh # some code for flux in $(ls -d /home/eai/*/*/*) ; do FICHIER=$(ls -p -tr $flux | ...
1
vote
1answer
1k views

Syntax error near unexpected token '{'

Every time I run new virtual terminal, it starts with bash: /usr/share/bash-completion/bash_completion: line 226: syntax error near unexpected token `}' bash: /usr/share/bash-completion/...
0
votes
2answers
300 views

tracking down an sh syntax error

I have a colleague who is connecting to a remote web host through a php/command line tool that the CMS Drupal uses called drush. Drush connects to the remote host through ssh, but when we issue ...
3
votes
2answers
70 views

Is the synopsis section of the man page for the find command wrong?

So, I have been trying to get into the habit of first looking at man pages before starting to google when I forget how to run a certain command. I was looking at the man page for the find command ...
4
votes
3answers
575 views

Correctly defining a Cron schedule for process to be run every hour

There is a record: 45 * * * 1 script.sh and 45 0-23 * * 1 script.sh The desired effect is to run the script 45 minutes after every hour on Mondays. Are they identical? If not, what is the ...
0
votes
2answers
96 views

Uunderstanding the redirections in this command? [duplicate]

I found a magic command here ./my.sh 3>all 1> >(tee out >&3) 2> >(tee err >&3) I am confused at some places: Does 3>all mean setting the file descriptor 3 for file ...
3
votes
1answer
542 views

Meaning of the double dash in options [closed]

I've read that all multi-character command options must be preceded by a double dash (--). But many flags for the find command (e.g. -name or -type) are preceded by only one dash. Why is that?
6
votes
2answers
708 views

Bash brace expansion to remove part of filename

Is it possible to remove rather than adding substring to a filename using bash brace expansion? Considering the following scenario, one can add a suffix to a filename by using the below technique: ...
5
votes
2answers
279 views

If [ is a builtin and [[ is a keyword, then what is ((?

According to this post, [ is a builtin and [[ is a keyword. Since they can be regarded as command, everything after [ and [[ is regarded as command arguments and should be separated by spaces, until ...
0
votes
1answer
333 views

Trying to exit script with a status code but getting “unexpected end of file”

I'm using bash shell on Amazon Linux. I can't figure out why my script is dying with a syntax error. My script ends like so chmod 775 $TFILE2 output_file=$( create_test_results_file "$TFILE2" ) (...
11
votes
1answer
2k views

What does !!: mean in bash? [duplicate]

Watching a video (https://vimeo.com/56166857 & https://www.youtube.com/watch?v=9CTfGS0gEOk @ 1m:34s), the presenter (TJ Holowaychuk) wrote: touch !!:2{...} I can't find what !!:2 means anywhere. ...
3
votes
3answers
486 views

Can a function in sh have zero statements?

Are there any relevant standards that dictate what an implementation of sh must do with an empty function? The following snippet defines a function with zero statements a() { } The subshell version ...
2
votes
1answer
249 views

syntax error in For loop script

I'm new in Linux and I also know this is a pretty common problem in the forum's questions but I have tried several options and I can't solve this issue. I am trying to execute the following script: !...
1
vote
0answers
192 views

Syntax error, unexpected ID [closed]

Why does this program throw a 'syntax error, unexpected ID'? #! /bin/bash ttl=30 alert="/home/pi/complete.oga" fail="/home/pi/bark.oga" begin_sound="/home/pi/robot-blip.wav" end_sound="/home/pi/...
2
votes
1answer
52 views

How many different variations of this command?

That's an unusual question. Let's say I have one command with this synopsis: /usr/bin/wc [-c | -m | -C] and second command with head [-number | -n number] [filename] The question is how many ...
-3
votes
1answer
604 views

arithmetic syntax error when install shell script

When I trying to install a software license server which is a shell script, I have an error and really don't know the way out. I cannot find any error in the script. Hope anyone can give me some help. ...
5
votes
1answer
1k views

null string as command in while loop: empty/null-command

I'm wondering how the while loop evaluates its loop condition. In the man page it is written: while list-1; do list-2; done The while command continuously executes the list list-2 as long as ...
-4
votes
1answer
247 views

How can you concatenate (or just combine) heredocuments (heredocs)? [closed]

Say I have to 2 heredocs. One runs in the foreground and it's counterpart runs right after it, in the background (&): bash -s -- $$ <<'EOF0' apt-get install phpmyadmin -y phpenmod mcrypt ...
0
votes
3answers
100 views

Run a command in the background but also concatenate other commands to it?

How could I concatenate several commands in a single line, but also run them all in the background ? These didn't work: sleep 1m & && echo "goodbye" & && exit &. sleep 1m ...
3
votes
1answer
167 views

Why ssh immediately disconnects when using -F /dev/stdin syntax?

I've configured and booted default Ubuntu VM box by the following commands: vagrant init ubuntu/trusty64; vagrant up --provider virtualbox Now, for education purposes, I'd like to use the following ...
1
vote
3answers
64 views

Use nested var for substitute var

I've a big question today ! I've made a little exemple of my situation. FOO="foo"; fooBAR="final"; var=${${FOO}BAR} echo $var I want to print "final". I tried all sort of things like ${${!FOO@}BAR} ...
1
vote
1answer
686 views

use loop variable for calculation bash

for i in {0..9} do T=$(bc<<<"8+$i*0.5") echo $T done I get : syntax error near unexpected token `T=$(bc<<<"8+$i*0.5")' I believe the problem is the $i. What am I doing ...
0
votes
1answer
3k views

Yet another syntax error near unexpected token `(' [closed]

This one different from the others as: I'm invoking bash (not sh) in the shebang: #! /bin/bash I'm running it with ./ File permissions are correct: 755 The line in question is: formattedTIME=`awk '...
3
votes
1answer
2k views

The repeat command syntax in zsh

I'm beginning with zsh and I use this manual. The syntax for repeat is presented as: repeat word do list done However I've noticed that: repeat 5 echo ok also works fine. Still, this omission ...