Tuesday, 29 May 2012

miriam_e: from my drawing MoonGirl (Default)
I missed the announcement of the "Cotton Candy" a few months back:
http://store.cstick.com/ <---there's a video demo of it on this page.
http://cstick.com/

This tiny desktop computer is somewhat more pricey than the VIA APC and the Raspberry Pi, but is faster and quite a bit smaller, fitting inside a USB stick case. I'd love one of these, but at $200 can't afford it. Nice though... USB jack at one end and HDMI video at the other. In between, Micro SD card slot and micro USB port. Inside is a Samsung 1.2GHz ARM Cortex A9-class processor, 1GB of memory, plus Bluetooth and Wi-Fi. [wistful sigh] As with increasing numbers of computers these days, it runs Android OS, which is really a kind of cut-down Linux.



miriam_e: from my drawing MoonGirl (Default)
Sign the petition (link below) to the Ukrainian President Viktor Yanukovych, asking him to denounce the proposed anti-gay bill that is in Parliament right now. This terrible law makes it a crime for anybody to read, write, blog about, or declare any kind of support for gay rights in Ukraine.

Millions of people around the world saw a photo last week of Svyatoslav, the organizer of Ukraine's Pride march, who was savagely beaten despite the cancellation of the event. The leader of Ukraine's opposition party is in jail right now because of the current government. We can create the kind of international exposure that is needed to focus attention squarely on the erosion of human rights conditions in Ukraine. Because when human rights begin to be abused, the first group to be targeted are usually LGBT people.

Please add your name to this letter, asking Ukrainian President Viktor Yanukovych to denounce this absurd anti-gay law and halt the spread of anti-gay sentiment throughout Ukraine.

http://www.allout.org/ukraine
miriam_e: from my drawing MoonGirl (Default)
The Linux shell can use the commands dirname and basename to separate out the name of a file from the path to it. If an extension is given with basename then you can get filename without the extension, however you need to know the extension ahead of time in order to specify it. If you want to strip the extension from a lot of files with many different extensions then this is of no use.

There is, however another, much better way. It is built into the bash command shell so no time and memory is wasted pulling in another command to do the job, and it is much more general-purpose, able to do far more than dirname and basename.

Here is a small script to show how it works. Seeing is much better than explaining:
#!/bin/sh

# get path, filename, basename, extension
# example: /mnt/drive/dir/file.tar.gz
pname="${1%/*}" ; # /mnt/drive/dir
fname="${1##*/}" ; # file.tar.gz
bname="${fname%%.*}" ; # file
b2name="${fname%.*}" ; # file.tar
ename="${fname##*.}" ; # gz
e2name="${fname#*.}" ; # tar.gz

echo "pname: $pname"
echo "fname: $fname"
echo "bname: $bname"
echo "b2name: $b2name"
echo "ename: $ename"
echo "e2name: $e2name"
Save the little script somewhere as someting like "testingstr". Make sure its permission bits are set to executable (chmod u+x testingstr) then run the script with a filename as its parameter, like this:
  ./testingstr /mnt/work/writing/back.tar.gz

The path and file name gets substituted into the script as "$1". The "%" tells to chop off from the end. The "#" tells to chop off from the beginning. A single "%" or "#" means to chop the shortest matching string. Doubled ("%%" or "##") means to match the longest possible string. The star ("*") is a wildcard; it stands in for any number of any characters. In the examples above, the dot or slash is the character being searched for to limit the string being chopped.

Read them like this:
${1%/*} in the parameter string ($1) chop the smallest possible string from the end that matches a slash followed by any other characters.

${1##*/} in the parameter string ($1) chop the longest possible string from the beginning that matches any characters followed by a slash.

${fname%%.*} in the previously computed string ($fname) chop the longest possible string from the end that matches a dot followed by any other characters.

You get the picture...

The bash shell can do many more string tricks too. For instance if you want to know the length of a string stored in a variable $x you can print it this way:
  echo "${#x}"

If you want to print a substring of a string variable from character 3 and going for 5 characters then use this form ${parameter:offset:length}:
  echo "${x:3:5}"

If you want to print from that point to the end of the string you don't need the length:
  echo "${x:3}"

You can do neat tricks using the length and substring to print the last n characters. For instance if you want the last single character then subtract one from the length and print the substring starting from that point onwards.
  x="blah"
  y=${#x}-1
  echo "${x:$y}"

prints the result:
  h


Or you can chop off the last number of characters from the string like this:
  x="gobble"
  y=${#x}-3
  echo "${x:0:$y}"

prints the result:
  gob


Lots of cool stuff... :)

Profile

miriam_e: from my drawing MoonGirl (Default)
miriam_e

February 2026

S M T W T F S
123 4 567
8910 11121314
15161718192021
22232425262728

Style Credit

Expand Cut Tags

No cut tags
Page generated Friday, 13 February 2026 08:30 am
Powered by Dreamwidth Studios