LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-11-2011, 09:31 PM   #1
RedNeck-LQ
Member
 
Registered: Jan 2011
Posts: 83

Rep: Reputation: 11
How to use the % symbol in bash shell scripts


Hello,

I am curios about this special symbol I see in some bash scripts. The character is the % character.

excerpt from a script

youtube-dl http://www.youtube.com/watch?v=oef9ZnnhMzc -o "%(title)s.flv"

excerpt from a script
mv "$i" "${i%.vob}.avi"

I understand the last one, where the vob extension is replaced by the avi extention. In the instance the % character is used to delete characters from the right that matches a pattern of .vob

The "%(title)s.flv" is what I don't understand. How is the % character in this instance?

I've search google on how to use this character in shell scripts but couldn't find anything. All I find is basic shell scripting guides.

If anyone has any links or know-how on using this character in shell scripts, please explain it to me.

much obliged

Last edited by RedNeck-LQ; 08-11-2011 at 09:39 PM.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 08-11-2011, 09:54 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

I don't usually respond to something when I DON'T know the answer...

... but in this case, I think it's probably appropriate.

Because ...

"%" is *NOT* a "metacharacter" in the shell. For example, "$PATH" indicates "the value of the shell variable "PATH". The DOS equivalent is "%PATH%". But the shell metacharacter is "$", not "%". "%" is NOT a shell metacharacter.

Similarly, "%" isn't a shell wildcard, either. For example, you "ls *.txt" will find all .txt files. "ls "?.txt" will find all one-character-prefix .txt files. The shell's wildcards are more extensive and more sophisticated than DOS wildcards ... but "%" isn't a wildcard character, either.

Finally, "%" IS used to designate shell "jobs". But it DOESN'T look like that's what you're referring to.

Soooooooooo .... "%" is a metacharacter or wildcard character ... in something BESIDES the bash shell.

For example:
Code:
http://bashscripts.proboards.com/index.cgi?board=bash&action=print&thread=55

lynx --dump "http://www.youtube.com/view_play_list?p=465C6C735CEB7CBD" | grep "watch?" | awk '{print $2}' | cut -d\& -f1 | sort -u | while read link;do youtube-dl -o "%(title)s.flv" "$link";done
  <= Here, "youtube-dl" parses the "%", not the shell
EDIT:
Diantre posted the answer to your question below. The "%" in question are youtube-dl "Output Templates". They're documented here:

http://rg3.github.com/youtube-dl/documentation.html#d7

Last edited by paulsm4; 08-12-2011 at 12:45 AM.
 
Old 08-11-2011, 10:42 PM   #3
RedNeck-LQ
Member
 
Registered: Jan 2011
Posts: 83

Original Poster
Rep: Reputation: 11
much obliged for the replay.

Quote:
Originally Posted by paulsm4 View Post
Soooooooooo .... "%" is a metacharacter or wildcard character ... in something BESIDES the bash shell.
So in other words, the youtube-dl app is using the % character as a wildcard and not the bash shell.

Still a bit confused...

BTW, do you know any links that explains this in more detailed.

if not, I appreciated the brief explanation you gave me.
 
Old 08-11-2011, 11:31 PM   #4
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
I suspect the issue is that % is a magic char for URLs for escaping unicode glyphs.
 
Old 08-12-2011, 12:08 AM   #5
Diantre
Member
 
Registered: Jun 2011
Distribution: Slackware
Posts: 515

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by RedNeck-LQ View Post
BTW, do you know any links that explains this in more detailed.
You can find documentation about Bash substring removal (${string%substring}) here. And documentation about youtube-dl output templates (%(NAME)s) in here.

Hope that helps.
 
2 members found this post helpful.
Old 08-12-2011, 02:01 AM   #6
RedNeck-LQ
Member
 
Registered: Jan 2011
Posts: 83

Original Poster
Rep: Reputation: 11
Quote:
Originally Posted by Diantre View Post
Hope that helps.
It greatly help, Diantre
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Shell Scripts thebigman101 Programming 5 04-16-2010 07:40 PM
Bash Shell Scripting *Integrate two scripts* Soulful93 Programming 1 04-29-2004 05:07 PM
bash shell scripts brisbois Linux - Newbie 3 02-17-2004 09:21 AM
Bash Shell Scripts Anthony Programming 2 03-29-2002 04:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration