Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question
    
I think that depends on the command -c -D could mean something in command 1 and a completly different thing in command 2. –  Uri Herrera Dec 6 '11 at 20:41
    
hey you changed the 1st command? where's the edit :X –  Rinzwind Dec 6 '11 at 20:46
    
I did change the 1st comment, because it was holding non-informative stuff. I'd like to show examples that are as relative as possible. I made an edit comment in the appropriate section for that. Thanks for the -c -D stuff, I get that. I updated the question. –  Exeleration-G Dec 6 '11 at 20:53
add comment

6 Answers

up vote 11 down vote accepted

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.

share|improve this answer
    
Advanced Bash-Scripting Guide - Chapter 3 is great. Thanks. –  Exeleration-G Dec 7 '11 at 13:08
    
The list in chapter 3 of the advanced bash-scripting guide is incomplete and partially wrong. The Advanced Bash Scripting guide is not a good resource for learning bash. See mywiki.wooledge.org/BashGuide and mywiki.wooledge.org/BashFAQ instead. –  geirha Mar 4 '12 at 0:12
    
@geirha I found ABS to be very helpful, but for the symbols in a specific command I like to look at the man pages instead, and your links are great too - bookmarked. Thanks. –  SaultDon Mar 4 '12 at 4:59
add comment

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.

share|improve this answer
    
OK, and what about >? That's a sign I see frequently as well, I thought it meant 'copy' or something. Is this one command-dependent as well? –  Exeleration-G Dec 7 '11 at 13:00
1  
@Exeleration-G See mywiki.wooledge.org/BashGuide/InputAndOutput#File_Redirection –  geirha Mar 4 '12 at 0:15
add comment

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.

share|improve this answer
    
That's very likely possible, because it's been taken from another question here. Without the context, it probably does nothing. –  Exeleration-G Dec 6 '11 at 20:54
add comment

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

share|improve this answer
add comment

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 http://tldp.org/LDP/abs/html/string-manipulation.html

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 : http://tldp.org/LDP/abs/html/testconstructs.html

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.