[SOLVED] Executing command from file (with tail) probably misquotes?
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.
Executing command from file (with tail) probably misquotes?
When working with a virtual terminal, I find it often easier to edit a file to execute than to construct a regular-expression etc. to inject the right UUID etc. into the command. I have run into an error while doing this. I suspect it is stems from quote mishandling, or improper escape sequences. (I ran directly from the command line earlier, forgot a quotation mark, and it gave a similar bad result.)
The program in question was efibootmgr. I had a file vaguely similar to this one, named efiboot.Hz:
efibootmgr -v revealed the previous command produced a garbled name and boot options, and most importantly it didn't boot. Manually writing the last line on the terminal did produce the desired effect. I thought I checked the output from tail before putting the back-ticks.
What did I do wrong?
You have to pipe the output to tail - if the log is in a file then you can use tail to skip forward and backward in the file - but with a pipe you can't.
If I understand correctly the shell normally evaluates the quote characters and splits up the arguments to the program accordingly, but when using backticks it immediately splits up the arguments. This page seems to suggest it is a quirk of the backticks. (But I've never run into problems otherwise, maybe because some programs check for interrupted arguments manually.)
If I understand correctly the shell normally evaluates the quote characters and splits up the arguments to the program accordingly, but when using backticks it immediately splits up the arguments.
It's a bit more complicated than that: token splitting happens first, then expansion, then word splitting on expansions, then quote removal on non-expansions. More details in the bash manual, specifically Shell-Operation and Shell-Expansions.
Quote:
Command split by printf:
The split is performed by the shell, not printf. This is significant because this splitting shows what any other command would see.
So the correct solution would be
Code:
eval "`tail -n 1 efiboot.Hz`"
The quotes around the backticks are important to avoid word-splitting twice. It doesn't matter for this particular command, but it's necessary if you want e.g. consecutive spaces in a single argument.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.