Ubuntu: how to extract the text between single quotes?


I'm running wallch to automatically cycle thru my wallpapers. I have hundreds of them. I created a little application that displays the title of a wallpaper:

export DISPLAY=:0 && /usr/bin/zenity --info --text="$(gsettings get org.gnome.desktop.background picture-uri | cut -c 41-)"  

Without the cut, the output is:


with the cut, I get the file name:


I want to get rid of the trailing apostrophe. I've tried various combinations of the cut --output-delimiter, but can't seem to get it to work.

I would be grateful if someone could point me to some code that would return just the file name.

Thanking all,



You could try

basename `gsettings get org.gnome.desktop.background picture-uri` \'  

assuming you are using BASH.

basename will extract the last name in the path, which is generated using your command to gsettings, put in backticks so it is seen as a command and not a string. The second argument to basename is the terminating characters you want to omit, in this case the apostrophe, which must be escaped using a backslash so it doesn't start a quote on the shell.


If you just want the file name, add:

| sed 's/\'//'  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »