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.
Questions tagged [syntax]
99 questions
48
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нιη
- 35,092
- 41
- 129
- 192
36
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
- 643
- 1
- 7
- 14
26
votes
4 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…
Mohammad Reza Rezwani
- 10,076
- 35
- 91
- 127
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
- 235
- 3
- 9
16
votes
7 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,071
- 7
- 26
- 32
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
- 19,653
- 18
- 73
- 128
15
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…
Abhishek Kamal
- 876
- 3
- 12
- 24
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
- 1
- 6
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
- 1
- 4
- 13
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
- 1
- 4
10
votes
2 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
- 111
- 1
- 1
- 6
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…
Konrad Viltersten
- 287
- 1
- 4
- 8
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
- 385
- 3
- 13
9
votes
5 answers
Why is a blank required between "[[" and "-e xxx" in ksh?
For instance, the following command does not work:
if [[-e xyz]]; then echo File exists;fi
ksh gives the following error
[[-e: command not found
Is that because "[[-" is ambiguous?
AcBap
- 93
- 4
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