Monday, April 29, 2024
12
rated 0 times [  12] [ 0]  / answers: 1 / hits: 26986  / 2 Years ago, mon, september 26, 2022, 12:57:47

What is the usage of the command quote? I haven't found any info about it, it isn't among the executable files in /bin folders, and it cannot be found among Bash built-ins. It seems that it only prints its first parameter, like an echo command and nothing more.


More From » command-line

 Answers
2

What is it?



I noticed that this command does not work in my shell (fish, friendly interactive shell). It seems like it does only work in bash (Ubuntu's default).



chocobai@pc ~> /bin/bash 
chocobai@pc:~$ quote asdf
'asdf'chocobai@pc:~$

chocobai@pc:~$ type quote
quote is a function.
quote ()
{
local quoted=${1//'/'''};
printf "'%s'" "$quoted"
}


What does it do? What can it be used for?



It adds the quotes but no newline. It also escapes single quotes in a way that's suitable for bash. It can be useful in scripts to quote a variable or some other kind of string. You need this for example for paths/parameters with spaces. Although there are other ways to do this.



It's really strange I could not find any documentation (in the web) about it. But well, it's easy to see what it does.


[#29132] Monday, September 26, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
terose

Total Points: 185
Total Questions: 125
Total Answers: 131

Location: Venezuela
Member since Mon, Dec 13, 2021
2 Years ago
terose questions
;