Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
"Another form of command substitution is `command`. The result is the same, except that the back quote (or backtick) syntax has some special rules..."
I followed the reference to the BASH manual for an explanation of the special rules here.
Does that mean the characters after the first \ here can be interpreted into something else as opposed to the literal meaning? Like what? I need some examples for that to be clearer.
>`\$;command`
>`\`;command`
>`\\`;command`
Lastly, what does this statement mean: The first backquote not preceded by a backslash terminates the command substitution.
Your context seems missing a bit. Assuming something is preceding the ">" and it's not just a command prompt symbol. But `` and $() are interchange-able. Except that $() allows for the nesting of commands. The \ char is an escape character. And the ; char is a line separator. With special chars like $ ^ ? and stuff. The non-special characters just get passed as an uninterpreted character less the preceding \.
I've noticed that the LFS books, when they need to nest two command substitutions, use backquotes for one and the $() construct for the other. They don't nest $() constructs. I suppose this is for reasons of legibility and comprehensibility.
Backquotes may be "the old way" but a lot of us still use them because it's that's the way we learned to do it.
I think backticks (meaning ``) for getting the results of a command should be consider "legacy baggage" at this point. And I always use the $() construct instead, even for nested calls. It's so much cleaner and easier to read. And there's no confusion about whether a backtick is opening a command or closing one.
Would work too. The -rv is just in case directories are present within the working directory, and output to term to see what's going on. If /home is actually meant to mean/home/user. In real world situations. What logical reasons would one have to put files in just the /home directory minus a user directory or subdirectory?
Quote:
>`\$;command`
>`\`;command`
>`\\`;command`
Lastly, what does this statement mean: The first backquote not preceded by a backslash terminates the command substitution.
to eliminate the termination just add another ` because they have to have an opening and closing, or matching pairs. I think they where just giving you a "matter of fact".
The LPI Certification In a Nutshell says:
Lastly, what does this statement mean: The first backquote not preceded by a backslash terminates the command substitution.
That's just an escape sequence. A backslash "escapes" the character. If you want to run a command containing a backtick (in this case) you will have to tell Bash to not interpret that backtick as the ending of command substitution clause. So you make the backtick literal with a backslash, making it lose its special meaning of ending your clause.
cp $(pwd) /home or cp `pwd` /home
is equivalent to:
cp /usr/my_pics /home
which copies my_pics folder to /home folder.
Backtick runs the contents of the enclosed string, and used it as a parameter to the other command on the line, in this case the "cp" command.
I think to save bytes use backtick, for clarity purposes use $().
that's not a good example.
it does not save any bytes either way.
also it will not work like this (cp throws a warning and doesn't copy anything, at least on my version).
i'd do it like this:
Code:
cp -r . /home
but you're likely to not have permission to copy anything to /home, i guess it really should be
Code:
cp -r . "$HOME"
and to "save bytes":
Code:
cp -r . ~
also, you usually don't need a command to get the present working directory, there's an env.variable called "$PWD", so this is equivalent:
Backtics are for portability. Even now, not all systems use bash unless the admins have installed it. Many have ksh/csh/sh (The Bourne shell) which don't use the $() construct.
A few of us even think bash is a bit bloated with things that shouldn't be there...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.