All Questions

Tagged with
0
votes
1answer
30 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
27 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
2answers
233 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 ...
-1
votes
1answer
93 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 ...
3
votes
2answers
589 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 $? ...
-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)...
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 ...
48
votes
3answers
8k 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
75 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
220 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 ...
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-...
1
vote
1answer
68 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
668 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
419 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 ...
0
votes
1answer
619 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 ...
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 ...
0
votes
1answer
100 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 ...
2
votes
2answers
344 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 ...
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 | ...
3
votes
1answer
247 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 ]] || [[ $...
5
votes
2answers
753 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() {...
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 ...
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
297 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 ...
6
votes
2answers
694 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
274 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
326 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. ...
2
votes
1answer
240 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
186 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/...
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 ...
1
vote
3answers
63 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
664 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 '...
14
votes
2answers
63k 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 ...