Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

What do these symbols in some Linux terminal commands mean? [closed]

Writer Sophia Terry

On AskUbuntu, I've seen a few commands around that look quite complicated, with lots of symbols in them. To get a better understanding of how these commands are built up, I'd like to know what the symbols stand for.

For example:

find ~/ -name \*.c -exec sed -i "s/cybernetnews/cybernet/g" {} \;

or even more complicated:

echo -e "\e[${i#*=}m$( x=${i%=*}; [ "${!x}" ] && echo "${!x}" || echo "$x" )\e[m"

I understand very well that adding parameters as -c, --debug, have certain effects on the main commmand. The meanings of these are in almost all cases to be found in the man pages, so that's not really what I'm looking for.

Please, try in your answer to define what the symbols specifically do, instead of explaining the examples I gave. That could look like this:

" means 'argument': the main command uses anything within these symbols as its source
^ is used for ...
# is used for ...

Thanks in advance

4

6 Answers

See The Bash Reference Manual section called Shell-Operation and the Advanced Bash-Scripting Guide Chapter 3 (Special Characters).

I refer to those anytime I need to learn something new about shell scripting in ubuntu/linux.

I think you will find ABS Chapter 3 the easiest to navigate for your purposes. All the symbols are seen on the far left of the page with a description immediately below them.

3

Unfortunately you do have to go to the man pages, as the "symbols" may have different meanings depending on which command is reading them.

For instance, in your first command, the meaning of {} and \; depend on the find command (man find). The meaning of quotes on an argument to sed are dependent on either sed or bash (as it's a quoted parameter it can potentially be a shell thing). The ~/ is definitely a bash pattern expansion thing.

For the second complicated command, it's mostly echoing stuff, so you'll find most information on that in bash's man page.

To answer your comment to this, the redirection characters > < | are used to pipe stuff from, and into, files (the greater and lesser than signs), and to connect a command's output with another's input (the pipe |). See here for a nice tutorial on I/O redirection, this is a very powerful design feature of the Unix shell and toolset.

2

1st one searches for files ending on .c from within directory ~/ and executes sed (streamline editor) where sed searches for cybernetnews and changes it into cybernet.

The 2nd one eludes me ... shows an empty result when executed.

1

The best resource I've found for learning terminal commands is LinuxCommand, it gives detailed descriptions of the most used commands available.

1

It is hard to tell you the full meaning of the symbols as you are pasting complex commands.

The echo in particular.

See man echo for the -e , it enables escape , so lateer \e is an escape.

The majority of the other symbols are string manipulations.

So imagine you have a variable, i which contains a string "foo"

i=foo;echo $i
foo

But it becomes more complex if your variable, $i, is also a part of a string

echo $ibar # Note: no output
echo ${i}bar # we have output
foobar

Now you can manipulate the strings as well, print only a part

In your case

${i#*=} = print $i , Strip out shortest match between * and = , but * itself is a wildcard ..

echo ${i#o}
foo
echo ${i#*o}
o

See

Next we hit a sub shell ( x ... )

Bash will process the commands in the sub shell and return the output of the commands.

x = (a sub string of i ) ; continue

Now we have a test , [ "${!x}" ]

See :

And here is where I can tell you no more.

In bash, ${!x} is going to be an empty string. && == logical and || is logical or

test {empty string} AND echo empty string or echo x

You would need to give more syntax, but it appears this echo is piping it's output somewhere.

Again [ ] is a test, and we escaped a [ at the very beginning.

So I can only explain so much of what the echo is doing.

The reason why there is no output when you enter the echo command in a terminal is it is a snipit of code, by default neither x or i is defined, so all the output is empty.

For questions about symbols in specific languages, you might want to try SymbolHound. You can search the web for characters that Google doesn't find.