Questions tagged [syntax]

Syntax refers to the rules of programming languages which stipulate how code is to be arranged so that the structure is syntactically correct and can be executed successfully in the particular framework of those languages.

104 questions
49
votes
3 answers

Write function in one line into ~/.bashrc

Why when I try to write a function just in one line into .bashrc file, list(){ ls -a } I get error? bash: /home/username/.bashrc: line num: syntax error: unexpected end of file but when I write it in multi line it's ok? list(){ ls -a }
αғsнιη
  • 36,350
40
votes
4 answers

How to format "if" statement (conditional) on multiple lines in bash?

I have a Bash shell function that takes an argument and performs something on it if needed. do_something() { if [need to do something on $1] then do it return 0 else return 1 fi } I want to call this method with several…
Itay
  • 693
28
votes
5 answers

What is the difference between standard syntax and BSD syntax?

I have seen many commands that accept a "BSD syntax" as well as their standard syntax. Take the ps command for one example: To see every process on the system using standard syntax: ps -e ps -ef ps -eF ps -ely To see every…
19
votes
8 answers

What is the point of the bash Null-operator ":", colon?

What is the point of the "null" operator in a BASH script? I understand that it is used as a placeholder following an if command when you have nothing to say, but need a command to allow the program to run properly. But what is the overall use for…
Justin
  • 2,151
  • 7
  • 29
  • 32
17
votes
2 answers

Run another command when previous command completes

Today I opened gnome-terminal and I wrote ls && sleep 4 && gnome-terminal to open another terminal after the completion of ls command and waiting for 4 seconds. So it successfully opened a new terminal after previous commands completely ran…
16
votes
3 answers

What does this syntax mean?

I am new to terminal and trying to learn how to use it. What do these lines do? And how do they work? echo -n "Today's date is: " date +"%A, %B %-d, %Y"
Unknown person
  • 335
  • 3
  • 9
15
votes
2 answers

What's the missing argument to -exec?

I use the following command to clear a directory, of files and directories over 30 days old, and move them to an archive directory which I can delete after a few weeks if nobody asks for their files back. The target directory has subdirectories by…
Arronical
  • 20,241
13
votes
2 answers

command output redirection using '-< <( ... )'

I needed to extract a shasum. This works, but can anyone explain why? sed 's/^.*= //' -< <(openssl dgst -sha256 filename) I'm familiar with the $( ) construct, but can't find docs for <( ), coupled with -<, which I assume is redirecting to the sed…
GlenH
  • 133
12
votes
2 answers

For loop with Alphabet

This works perfectly on OSX #!/bin/bash chars=( {a..z} ) n=3 for ((i=0; i
denski
  • 331
11
votes
3 answers

"Syntax error: Unterminated quoted string"

I am trying to use a backup script that will backup my sql database and website files. I am running Ubuntu 12.04 32 bit version and zPanel. Also what are these variables: MYSQL="$()" MYSQLDUMP="$()" GZIP="$()" I assume the first one is DB…
Hamza
  • 121
11
votes
2 answers

meaning of "'" (apostrophe) in terminal commands

For some weird reason, I tried "'" as word separator in identifiers, as in: $ export foo'bar=1 > > ^C $ The result is as shown above, id est the prompt changes to ">" and the system obviously waits for more information on my part. As you see, I…
denis 63
  • 111
10
votes
1 answer

What does the syntax of pipe and ending dash mean?

Disclaimer. I'm a long-time Windows user and just starting to get my head around the Linux paradigm. While excited by it, I understand that my formulations might be poorly chosen due to ignorance. I've received an answer, the contents of which…
9
votes
1 answer

Brackets, Braces, Curly Brackets in Bash

Here goes the riddle: If I do: touch file{1,2,3} It creates file1, file2, file3 And if I do rm file[1-3] It deletes them. but if I do touch file[1-3] it creates: file[1-3] Why?
Ulukai
  • 425
  • 1
  • 6
  • 14
9
votes
3 answers

how do I fix youtube-dl: running it gives error message about incorrect syntax

I recently installed 22.04 completely from scratch. Just now I followed instructions to install youtube-dl, with wget (from github.com): sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl sudo chmod a+rx…
Akpglt
  • 113
  • 1
  • 1
  • 5
8
votes
1 answer

Can I enable bracket matching in nano?

else if( d && ( (d <= b && d <= s) || (!b && !s) ) smallest = d Consider this piece of code of C++. Can we have bracket matching (highlighting opening bracket when cursor on closing bracket & vice versa)?
owsmmj
  • 301
  • 2
  • 7
1
2 3 4 5 6 7