Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [syntax]

The tag has no usage guidance.

0
votes
1answer
22 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
28 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
1answer
92 views

flock command script fail on xunbuntu 16.04 - cant understad why

#!/bin/bash ( flock -n 200 || exit 1 # commands executed under lock sleep 3 echo "TEST" ) 200 > /home/nis/Scripts/lock.txt Running this scrip gets me this error: lock.sh: 7: lock.sh: ...
0
votes
0answers
26 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 ...
1
vote
1answer
97 views

Concerning AWK programming, what do the -f switch and ~ operator do? [closed]

I can't seem to find anything on these switches. I know the "-F" option can be used to change the delimiter but that's the extent of what I've found other than it looks like maybe a compiling option; ...
0
votes
1answer
16 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/...
27
votes
4answers
3k views

Are if else statement equivalent to logical and && or || and where should I prefer one over the other?

I'm learning about decision making structures and I came across these codes: if [ -f ./myfile ] then cat ./myfile else cat /home/user/myfile fi [ -f ./myfile ] && cat ./myfile || ...
0
votes
2answers
222 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
80 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 ...
0
votes
1answer
84 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
2answers
2k views

[line 35 unexpected EOF while looking for matching ' " ' and line 40 unexpected end of file]

This is my homework to write calculator on shell script but there is two errors and I couldn't find the solutions. echo "---------Welcome to Simple Calculator--------" echo "p=PLUS" echo "m=MINUS" ...
2
votes
0answers
32 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 ...
1
vote
1answer
4k views

Running R script via shell script. syntax error near unexpected token `('

I am currently trying to run an R script via a shell script. Here the R script: test = rnorm(1:100, 1000) write.csv(test, 'test.csv') And here the bash script which calls the R one: #!/bin/bash -l ...
0
votes
1answer
314 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 ...
2
votes
1answer
142 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://...
0
votes
1answer
20 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://...
-9
votes
5answers
1k views

What is masking a mode? [closed]

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

How to create softlink for a file /var/log/messages on /root/Desktop with same name using ln command

Which one should be the target and which one be the link name? Update 1: I am logged in as super user, and I also got to know to access root folder using GUI.
3
votes
2answers
545 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
2answers
229 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
0answers
30 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 ...
3
votes
1answer
86 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
158 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
73 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 ...
-1
votes
2answers
218 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 ...
16
votes
1answer
2k 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
97 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 ...
6
votes
4answers
1k 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 -...
48
votes
3answers
7k 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 ...
-1
votes
5answers
251 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 ...
2
votes
0answers
73 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=...
0
votes
1answer
18 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
212 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
vote
1answer
125 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-...
0
votes
1answer
558 views

-e option in command grep

I encountered a problem when reading grep manual refering to it -e option, It say: -e pattern, --regexp=pattern Specify a pattern used during the search of the input: an input line ...
1
vote
1answer
66 views

How to Define Custom Conditional Expression Primaries in Bash?

How would I redefine and/or define new conditional expression primaries in bash? For example, I would like a primary that tests for the existence of an empty directory. Of course, it would be ...
0
votes
1answer
2k views

Rsync include from and exclude from a list

I am trying to use rsync include-from and exclude-from commands to ignore or only copy listed files/directories from a source. The list is in a text file. For some reason the command does not execute. ...
0
votes
1answer
643 views

How does pushd work?

In Ubuntu 16.04 with Bash I had a problem when I didn't have a convenient way to upgrade all my WordPress components (core, translations, theme, plugin) and I used the following code to solve it: cat ...
1
vote
1answer
395 views

List of acceptable initial characters for a bash variable

What are the acceptable characters in a bash variable? Can someone point me to the place in the bash man page that describes the acceptable name for a bash variable? I looked and came up with a lot ...
11
votes
6answers
2k views

Too many shebang (script declaration) lines — any way to reduce their amount?

I have a project comprised of about 20 small .sh files. I name these "small" because generally, no file has more than 20 lines of code. I took a modular approach because thus I'm loyal to the Unix ...
0
votes
1answer
607 views

Concatenating a list of files using For loop

I'm new to unix/bash/code in general, and I'm trying to merge multiple sample files with the same name in different directories into a new file in its own directory (the outputs of multiple data ...
1
vote
1answer
3k views

shell script error : Syntax error: “(” unexpected

I have checked the previous post on this error. still did not get the solution working. Here is my bash script. can some one help me figure out the issue . I have used https://www.shellcheck.net/ to ...
0
votes
1answer
99 views

Execution of a remote Bash script in GitHub fails with various methods - Maybe due to Windows10

I have this remote Bash script In GitHub that I already executed successfully line by line, several times (in different versions). As it is quite frustrating to copy paste all lines each test, I ...
3
votes
5answers
169 views

How to execute many files in the same directory in a minimal, DRY, pretty way?

I use Ubuntu 16.04 and I have a localization file, a file that executes many files, that I got after downloading my own GitHub project to my machine. This file contains a Bash script, and is named ...
8
votes
2answers
513 views

When is it useful to use “grep — SOMEPATTERN”?

Under Linux/AIX where ever, when is it useful to use --, as in this command: grep -- SOMEPATTERN
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 ...
2
votes
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
420 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
190 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
1k 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 ...