LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   I have a specific linux bash question about variables and possible hexadecimals. (http://www.linuxquestions.org/questions/linux-software-2/i-have-a-specific-linux-bash-question-about-variables-and-possible-hexadecimals-907049/)

darkstarbyte 10-08-2011 12:00 AM

I have a specific linux bash question about variables and possible hexadecimals.
 
So I have season one of bleach and it is separated into 5 disks. I have xbmc and I wanted to take a library and add all of my episode from one directory into one file called videodb.xml Which is with in xbmc_videodb_2011-10-08 which is within my bleach folder in my home folder. I found the file names requires different id's for each video I have. Before we go any farther I encoded them into the avi format which I researched to be compliant with the xbox 360.

I put some notes in the shell script.

Code:


#!/bin/bash

echo "<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>" >> xbmc_videodb_2011-10-08/videodb.xml
echo "<videodb>" >> xbmc_videodb_2011-10-08/videodb.xml

a=xx00000000 # This is the starting address
for i in ./*
{
    a++ # I don't know how to make this count up from the starting
######### address so that it does this xx00000000 to xx0000001 and
######### so on.
    echo "    <movie>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <title>$i</title>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <rating>0.000000</rating>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <epbookmark>0.000000</epbookmark>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <year>0</year>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <top250>0</top250>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <votes></votes>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <outline></outline>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <plot></plot>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <tagline></tagline>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <runtime></runtime>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <mpaa></mpaa>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <playcount>0</playcount>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <lastplayed></lastplayed>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <file></file>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <path>/home/branden/Bleach.Episodes.1-222.Movie.1-2.plus.OVA.japdub.engsub/</path>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <filenameandpath>/home/branden/Bleach.Episodes.1-222.Movie.1-2.plus.OVA.japdub.engsub/$i</filenameandpath>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <id>$a</id>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <genre>Anime</genre>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <premiered></premiered>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <status></status>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <code></code>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <aired></aired>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "        <trailer></trailer>" >> xbmc_videodb_2011-10-08/videodb.xml
    echo "    </movie>" >> xbmc_videodb_2011-10-08/videodb.xml
}

echo "    <paths />" >> xbmc_videodb_2011-10-08/videodb.xml
echo "</videodb>" >> xbmc_videodb_2011-10-08/videodb.xml


Kenhelm 10-08-2011 08:01 AM

This counts up in hexadecimal.
Code:

a=xx00000000
for i in ./*; do
  atmp=${a/x/0}  # Change first 'x' to '0'
  a=$(printf 'xx%08X' $((++atmp)) )
#        use 'xx%08x' for lower case A-F
  echo $a
done

xx00000001
xx00000002
xx00000003
xx00000004
xx00000005
xx00000006
xx00000007
xx00000008
xx00000009
xx0000000A
xx0000000B
xx0000000C
xx0000000D
xx0000000E
xx0000000F
xx00000010


darkstarbyte 11-13-2011 01:14 AM

I did not respond for a while, but yes it worked.

grail 11-13-2011 03:20 AM

May I also suggest you look up here documents instead of so many echo lines.


All times are GMT -5. The time now is 03:45 AM.