<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel>
	  <title>Ask MetaFilter questions tagged with bash</title>
      <link>http://ask.metafilter.com/tags/bash</link>
      <description>Questions tagged with 'bash' at Ask MetaFilter.</description>
	  <pubDate>Tue, 11 Aug 2009 16:29:56 -0800</pubDate> <lastBuildDate>Tue, 11 Aug 2009 16:29:56 -0800</lastBuildDate>

      <language>en-us</language>
	  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
	  <ttl>60</ttl>	  
	<item>
	<title>Bash scripting problem</title>
	<link>http://ask.metafilter.com/129891/Bash%2Dscripting%2Dproblem</link>	
	<description>Please hope me with a bash scripting problem. Involves: command substitution and word splitting. In my script I&apos;m trying to wrap the curl command to give it a global retry value. So I have &lt;a href=&quot;http://pastebin.com/f16c6268b&quot;&gt;this&lt;/a&gt;.&lt;br&gt;
&lt;br&gt;
When I call it like this, things seem to work:&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;retry_curl &quot;http://example.org/file1.txt&quot;&lt;/pre&gt;&lt;br&gt;
&lt;br&gt;
But I have one place where I want to call it like this:&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;LOCAL_CURLOPTS=&quot;--time-cond \&quot;Tue, 11 Aug 2009 18:12:12 -0500\&quot;&quot;&lt;br&gt;
retry_curl $LOCAL_CURLOPTS &quot;http://example.org/file1.txt&lt;/pre&gt;&lt;br&gt;
&lt;br&gt;
And what I get on the console is:&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;curl: option -0500: is unknown&lt;br&gt;
curl: try &apos;curl --help&apos; or &apos;curl --manual&apos; for more information&lt;/pre&gt;&lt;br&gt;
&lt;br&gt;
So somewhere bash is breaking apart my LOCAL_CURLOPTS as words, and then using that in the command substitution. What I can&apos;t figure out is how to get it to stop.</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2009:site.129891</guid>
	<pubDate>Tue, 11 Aug 2009 16:29:56 -0800</pubDate>
	<category>bash</category>
	<category>command</category>
	<category>resolved</category>
	<category>substition</category>
	<category>words</category>
	<dc:creator>sbutler</dc:creator>
	</item>
	<item>
	<title>Shell script handling CSV columns</title>
	<link>http://ask.metafilter.com/124463/Shell%2Dscript%2Dhandling%2DCSV%2Dcolumns</link>	
	<description>I&apos;m using a shell script to handle some excel docs by converting to csv and reformatting it a little bit. I&apos;m having some difficulty going on with the next part of the script. Some help would be great. :) CURRENT SCRIPT:&lt;br&gt;
#!/bin/sh&lt;br&gt;
ls *.xls&lt;br&gt;
echo &quot;Enter filename for excel input file: &quot;&lt;br&gt;
read filen&lt;br&gt;
xls2csv -x &quot;$filen&quot;&quot;.xls&quot; -b WINDOWS-1252 -c &quot;$filen&quot;&quot;.csv&quot; -a UTF-8&lt;br&gt;
sed &apos;1,3d&apos; &quot;$filen&quot;.csv &amp;gt;&quot;$filen&quot;_temp.csv&lt;br&gt;
cut -d &quot;,&quot; -f 1,4- &quot;$filen&quot;_temp.csv &amp;gt; &quot;$filen&quot;_temp2.csv&lt;br&gt;
awk -F, &apos;{sub($NF, &quot;&quot;);print}&apos; &quot;$filen&quot;_temp2.csv &amp;gt; &quot;$filen&quot;_temp3.csv&lt;br&gt;
sed &apos;s/.$//&apos; &quot;$filen&quot;_temp3.csv &amp;gt; &quot;$filen&quot;_fixed.csv&lt;br&gt;
rm &quot;$filen&quot;.csv&lt;br&gt;
rm &quot;$filen&quot;_temp.csv&lt;br&gt;
rm &quot;$filen&quot;_temp2.csv&lt;br&gt;
rm &quot;$filen&quot;_temp3.csv&lt;br&gt;
echo &quot;$filen&quot;&quot;.xls corrected and saved as &quot;&quot;$filen&quot;&quot;_fixed.csv&quot;&lt;br&gt;
&lt;br&gt;
EXAMPLE OUTPUT (first three lines only):&lt;br&gt;
&quot;Device ID&quot;,&quot;1) S31 Which best describes how you answered the online reading comprehension quiz?&quot;,&quot;2) S32 Which best describes how you answered the online timed retrieval quiz?&quot;,&quot;3) B19. If you want your product to be easy to find in the supermarket then you should make its container&quot;,&quot;4) C19.  So that he can shift attention between the radio and his incessantly talking girl friend when she is in the car, Joe adjusts his radio&quot;,&quot;5) B20.  Early selection is most likely to occur for&quot;,&quot;6) C20.  Early selection for a red target is most likely to occur when there is&quot;,&quot;7) B21. In a lexical decision task, when the target is a bird name, e.g. robin, it is usually preceded by the prime BODY but is sometimes preceded by the prime BIRD.&quot;,&quot;8) C21.  In a lexical decision task, when the target is a dog name, e.g. collie, it is usually preceded by the prime CAR but is sometimes preceded by the prime DOG.&quot;,&quot;9) B23. Suppose that that you see a brief display with 12 colored letters: 4 red, 4 white, and 4 blue.  At the offset of the display you hear tone.  A tone instructs you to report only the letters of a particular color: high for red, medium for white, and low for blue.  About how many letters do you report?&quot;,&quot;10) B22.  Sperling (1960) found that partial report produced the highest estimate of the number of available letters when the tone occurred &quot;,&quot;11) C23.  According to the logic of Sperling&#8217;s (1960) partial report method, an observer who reports three letters from a row in a 4 x 4 display that was cued at the display&#8217;s offset must have seen at least&quot;,&quot;12) C22.  Sperling (1960) found that the greatest difference between full and partial report in the number available of letters was when the tone occurred ____ milliseconds after the offset of the visual display&quot;&lt;br&gt;
96A39,6,4,&quot;4 c&quot;,&quot;4 c&quot;,&quot;5 c&quot;,&quot;5 c&quot;,&quot;5 c&quot;,&quot;4 i&quot;,&quot;3 c&quot;,&quot;1 c&quot;,&quot;1 i&quot;,&quot;5 i&quot;&lt;br&gt;
1E90A4,5,3,&quot;4 c&quot;,&quot;4 c&quot;,&quot;5 c&quot;,&quot;5 c&quot;,&quot;2 i&quot;,&quot;5 c&quot;,&quot;3 c&quot;,&quot;1 c&quot;,&quot;4 i&quot;,&quot;4 i&quot;&lt;br&gt;
&lt;br&gt;
First, I need to remove the numbering of the questions from the first line. So &quot;1) S31 Which best describes how you answered the online reading comprehension quiz?&quot; would become &quot;S31 Which best describes how you answered the online reading comprehension quiz?&quot;&lt;br&gt;
&lt;br&gt;
Next I need to remove an entire column if its row header doesn&apos;t begin with either B or C or is the &quot;Device ID&quot; column. For example, column starting with B19 is kept, the C23 is kept, and&quot;Device ID&quot; column is kept. The column with the question starting S31 must be entirely removed.&lt;br&gt;
&lt;br&gt;
Thanks.</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2009:site.124463</guid>
	<pubDate>Wed, 10 Jun 2009 16:30:20 -0800</pubDate>
	<category>bash</category>
	<category>csv</category>
	<category>excel</category>
	<category>grep</category>
	<category>linux</category>
	<category>perl</category>
	<category>regexp</category>
	<category>regularexpression</category>
	<category>script</category>
	<category>shell</category>
	<category>unix</category>
	<dc:creator>fightoplankton</dc:creator>
	</item>
	<item>
	<title>Joining MP3 Files Together Based on Date in Filename?</title>
	<link>http://ask.metafilter.com/117747/Joining%2DMP3%2DFiles%2DTogether%2DBased%2Don%2DDate%2Din%2DFilename</link>	
	<description>I have a podcast that downloads as multiple segments over multiple days.  Its format arrives as YYYYMMDD_showcode_segment.mp3; so, for example, one download might result in files as 20090323_goofa_01.mp3 through 20090323_goofa_21.mp3, and also &lt;i&gt;within the same download&lt;/i&gt; 20090324_goofa_01.mp3 through 20090324_goofa_21.mp3.  What I&apos;m looking for is a Unix script (shell, perl, what have you) that would look at a directory and look at what dates are represented there, and let me join all of the segments together by day.  I can use mpgtx -j to do the actual joining; I&apos;m looking for the code that would let the script determine what dates are in the directory and then get each day&apos;s segments united into a single MP3 for that day&apos;s show.</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2009:site.117747</guid>
	<pubDate>Wed, 25 Mar 2009 16:08:55 -0800</pubDate>
	<category>bash</category>
	<category>csh</category>
	<category>day</category>
	<category>group</category>
	<category>join</category>
	<category>mp3</category>
	<category>perl</category>
	<category>resolved</category>
	<category>script</category>
	<category>segment</category>
	<category>tcsh</category>
	<category>unix</category>
	<dc:creator>WCityMike</dc:creator>
	</item>
	<item>
	<title>BASH: Handling odd characters in a variable?</title>
	<link>http://ask.metafilter.com/107165/BASH%2DHandling%2Dodd%2Dcharacters%2Din%2Da%2Dvariable</link>	
	<description>BASH Scripting.  I&apos;m trying to do a simple &quot;mv&quot; operation with a not-so-simple filename that contains special characters (as in brackets and hyphens).  The filename itself is stored within a variable.  The operation fails, and I can understand why, but I don&apos;t know how to get around it. A sample filename would be something like:&lt;br&gt;
&lt;br&gt;
[2008] Region {XX}.pdf&lt;br&gt;
&lt;br&gt;
...and is stored in $sFilename.  Not all of the filenames are the same format although all of them start with the year in square brackets.&lt;br&gt;
&lt;br&gt;
I&apos;ve got the rest of the script set up to parse for the year in the initial set of [ ] brackets and create a folder (./2008) with that name.  The second part of the script is supposed to move the aforementioned file into the created folder.  I attempt to do this with the command:&lt;br&gt;
&lt;br&gt;
&lt;i&gt;mv &quot;$sFilename&quot; ./$sPrefix&lt;/i&gt;&lt;br&gt;
&lt;br&gt;
...where $sPrefix is the parsed item from the brackets.  It errs out with the message:&lt;br&gt;
&lt;br&gt;
&lt;i&gt;mv: cannot stat `[2008]&apos;: No such file or directory.&lt;/i&gt;&lt;br&gt;
&lt;br&gt;
It seems to me the shell is choking on the filename.  What&apos;s the best way to work around this WITHOUT renaming the files (since the program that imports them is Windows-based and requires they be intact)?&lt;br&gt;
&lt;br&gt;
Thanks</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2008:site.107165</guid>
	<pubDate>Tue, 18 Nov 2008 13:58:55 -0800</pubDate>
	<category>bash</category>
	<category>BashScripting</category>
	<category>scripting</category>
	<dc:creator>Ziggy Zaga</dc:creator>
	</item>
	<item>
	<title>How do I tell my Mac that I&apos;m me?</title>
	<link>http://ask.metafilter.com/104310/How%2Ddo%2DI%2Dtell%2Dmy%2DMac%2Dthat%2DIm%2Dme</link>	
	<description>Question about changing my terminal prompt (and other matters) in an OS X Bash shell. I&apos;m not the most experienced Unix guy, but I can usually figure things out. But this one has me stumped: I just got a slightly-used Macbook Pro. The previous ower -- Michael -- gave me his admin password. So I went into System Preferences, Accounts and created a new admin, grumblebee. Then I deleted Michael.&lt;br&gt;
&lt;br&gt;
All went well until I opened terminal, where I saw that the prompt looked like this:&lt;br&gt;
&lt;br&gt;
michaels-mackbook-pro: ~Grumblebee&lt;br&gt;
&lt;br&gt;
(I know that ~Grumblebee isn&apos;t part of the prompt. I just wanted to show you that I&apos;m logged in as me and it&apos;s finding my home directory. It&apos;s just the prompt that&apos;s wrong.)&lt;br&gt;
&lt;br&gt;
I tried to edit etc/baschrc, but it said I didn&apos;t have permission.&lt;br&gt;
&lt;br&gt;
How can I change the prompt and is it likely I&apos;ll encounter any other problems connected to changing users?</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2008:site.104310</guid>
	<pubDate>Wed, 15 Oct 2008 07:17:27 -0800</pubDate>
	<category>accounts</category>
	<category>apple</category>
	<category>bash</category>
	<category>linux</category>
	<category>mac</category>
	<category>macbook</category>
	<category>osx</category>
	<category>prompt</category>
	<category>resolved</category>
	<category>shell</category>
	<category>unix</category>
	<category>users</category>
	<dc:creator>grumblebee</dc:creator>
	</item>
	<item>
	<title>What resources do you guys recommend on learning to BASH script, and also learn from other peoples code?</title>
	<link>http://ask.metafilter.com/103992/What%2Dresources%2Ddo%2Dyou%2Dguys%2Drecommend%2Don%2Dlearning%2Dto%2DBASH%2Dscript%2Dand%2Dalso%2Dlearn%2Dfrom%2Dother%2Dpeoples%2Dcode</link>	
	<description>What resources do you guys recommend on learning to BASH script, and also learn from other peoples code? Hey guys, I am quite interested in learning to Bash script and was wondering what guides you guys thought were the best suited for this task. Also, since learning by example works better for me any resources that taught this way would also be much appreciated.&lt;br&gt;
&lt;br&gt;
On the other hand I also realize that learning from actually programming is the much better way, so if there were any sites that like gave you a problem to solve in bash and gave a sample solution to that problem would be the best! Also a nice place to look at others Bash code to learn from it would also be much appreciated.</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2008:site.103992</guid>
	<pubDate>Sat, 11 Oct 2008 09:02:50 -0800</pubDate>
	<category>bash</category>
	<dc:creator>Javed_Ahamed</dc:creator>
	</item>
	<item>
	<title>Quicksilver-style completion in bash shell?</title>
	<link>http://ask.metafilter.com/96319/Quicksilverstyle%2Dcompletion%2Din%2Dbash%2Dshell</link>	
	<description>How can I get Quicksilver-style completion in the bash shell? Suppose I have a bunch of files in a directory. One of them is named &apos;metafilter&apos;. I&apos;d like to say &lt;b&gt;cat mflr&lt;/b&gt;&lt;i&gt;[TAB]&lt;/i&gt; and have that be expanded.&lt;br&gt;
&lt;br&gt;
I &lt;i&gt;think&lt;/i&gt; this is equivalent to asking for an implicit * between each typed character.&lt;br&gt;
&lt;br&gt;
Anyone have bash-completion-fu?</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2008:site.96319</guid>
	<pubDate>Fri, 11 Jul 2008 06:44:57 -0800</pubDate>
	<category>bash</category>
	<category>quicksilver</category>
	<category>resolved</category>
	<category>shell</category>
	<category>unix</category>
	<dc:creator>dmd</dc:creator>
	</item>
	<item>
	<title>How to delete long path names with bash shell script?</title>
	<link>http://ask.metafilter.com/93056/How%2Dto%2Ddelete%2Dlong%2Dpath%2Dnames%2Dwith%2Dbash%2Dshell%2Dscript</link>	
	<description>BASHFilter! I&apos;ve got a simple bash script that I&apos;ve written to clean out a frequently used NAS. I run it every 30 days, it sets proper permissions, removes extraneous files and directories, but it frequently hangs on paths longer than 255 characters. I&apos;m no bash ninja, so I&apos;ve been beating my head against a wall trying to figure out how to check path length of directories, and then prompt for either renaming to shorten them, or prompt for deletion. Help me Metafilter!</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2008:site.93056</guid>
	<pubDate>Mon, 02 Jun 2008 22:07:17 -0800</pubDate>
	<category>bash</category>
	<category>linux</category>
	<category>script</category>
	<category>shell</category>
	<dc:creator>jackofsaxons</dc:creator>
	</item>
	<item>
	<title>Help installing Debian Etch?</title>
	<link>http://ask.metafilter.com/92216/Help%2Dinstalling%2DDebian%2DEtch</link>	
	<description>Okay I&apos;m trying to set up rtorrent and wtorrent using Debian Etch and &lt;a href=&quot;http://flipsidereality.com/blog/linux/rtorrent-with-wtorrent-on-debian-etch-complete-howto/&quot;&gt;this guide&lt;/a&gt;. Installs and updates the kernel fine, then I get &quot;bash command not found&quot; when trying to run through the rest of the tutorial. I tried this from a blank slate twice. I must be missing something stupid. My Linux knowledge is limited but I&apos;ve setup wikis and things just fine. It is running on VMWare ESX as &quot;Other Linux (32-bit)&quot; ... it updated the kernel without incident, and I have SSH running. When I terminal in as root:&lt;br&gt;
&lt;blockquote&gt;rtorrent:~# apt-get install apache-common apache2-utils autoconf automake \&lt;br&gt;
&amp;gt;&lt;br&gt;
autotools-dev binutils build-essential bzip2 ca-certificates comerr-dev \&lt;br&gt;
&lt;br&gt;
cpp cpp-4.1 dpkg-dev file g++ g++-4.1 gawk gcc gcc-4.1 libapache-mod-php5 \&lt;br&gt;
&lt;br&gt;
libapr1 libaprutil1 libc6-dev libcurl3 libcurl3-openssl-dev libexpat1 \&lt;br&gt;
 eading package lists... 0%&lt;br&gt;
Reading package lists... Done&lt;br&gt;
libidn11 libidn11-dev libkadm55 libkrb5-dev libmagic1 libncurses5-dev \&lt;br&gt;
 uilding dependency tree... 0%&lt;br&gt;
libneon26 libpcre3 libpq4 libsigc++-2.0-dev libsqlite0 libsqlite3-0 \&lt;br&gt;
&lt;br&gt;
libssl-dev libssp0 libstdc++6-4.1-dev libsvn1 libtool libxml2 lighttpd \&lt;br&gt;
&lt;br&gt;
linux-kernel-headers lynx m4 make mime-support ntp ntpdate openssl patch \&lt;br&gt;
&lt;br&gt;
perl perl-modules php5 php5-cgi php5-common php5-sqlite pkg-config screen \&lt;br&gt;
&lt;br&gt;
Building dependency tree... Done&lt;br&gt;
apache-common is already the newest version.&lt;br&gt;
apache2-utils is already the newest version.&lt;br&gt;
autoconf is already the newest version.&lt;br&gt;
automake is already the newest version.&lt;br&gt;
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.&lt;br&gt;
rtorrent:~# autotools-dev binutils build-essential bzip2 ca-certificates comerr-dev \&lt;br&gt;
&amp;gt;&lt;br&gt;
-bash: autotools-dev: command not found&lt;br&gt;
rtorrent:~# cpp cpp-4.1 dpkg-dev file g++ g++-4.1 gawk gcc gcc-4.1 libapache-mod-php5 \&lt;br&gt;
&amp;gt;&lt;br&gt;
-bash: cpp: command not found&lt;br&gt;
rtorrent:~# libapr1 libaprutil1 libc6-dev libcurl3 libcurl3-openssl-dev libexpat1 \&lt;br&gt;
&amp;gt;&lt;br&gt;
-bash: libapr1: command not found&lt;br&gt;
rtorrent:~# libidn11 libidn11-dev libkadm55 libkrb5-dev libmagic1 libncurses5-dev \&lt;br&gt;
&amp;gt;&lt;br&gt;
-bash: libidn11: command not found&lt;br&gt;
rtorrent:~# libneon26 libpcre3 libpq4 libsigc++-2.0-dev libsqlite0 libsqlite3-0 \&lt;br&gt;
&amp;gt;&lt;br&gt;
-bash: libneon26: command not found&lt;br&gt;
rtorrent:~# libssl-dev libssp0 libstdc++6-4.1-dev libsvn1 libtool libxml2 lighttpd \&lt;br&gt;
&amp;gt;&lt;br&gt;
-bash: libssl-dev: command not found&lt;br&gt;
rtorrent:~# linux-kernel-headers lynx m4 make mime-support ntp ntpdate openssl patch \&lt;br&gt;
&amp;gt;&lt;br&gt;
-bash: linux-kernel-headers: command not found&lt;br&gt;
rtorrent:~# perl perl-modules php5 php5-cgi php5-common php5-sqlite pkg-config screen \&lt;br&gt;
&amp;gt;&lt;br&gt;
Can&apos;t open perl script &quot;perl-modules&quot;: No such file or directory&lt;br&gt;
rtorrent:~# sqlite subversion ucf zlib1g-dev&lt;/blockquote&gt;Buh. I searched around and it looks like there might be something wrong with my Bash profile? What am I doing wrong here?&lt;br&gt;
&lt;br&gt;
rtorrent:~# echo $PATH&lt;br&gt;
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2008:site.92216</guid>
	<pubDate>Fri, 23 May 2008 10:03:32 -0800</pubDate>
	<category>bash</category>
	<category>debian</category>
	<category>linux</category>
	<dc:creator>geoff.</dc:creator>
	</item>
	<item>
	<title>OS X file permissions issue</title>
	<link>http://ask.metafilter.com/91968/OS%2DX%2Dfile%2Dpermissions%2Dissue</link>	
	<description>OS X Sites folder permissions and a question about flags on the files in bash. What gives? I use my MacBook Pro as a test server, running Apache. I sync my files (two-way sync, using Chronosync) between my Mac and my home Windows system. Sometimes after a sync my test site breaks - I don&apos;t have permission to access my own files. Sure, a chmod -R 755 * on my Sites folder fixes it, but why is it happening? I don&apos;t need to have files at 755 for them to work on my Linux server, so why does the Mac refuse to deliver any CSS or javascript files unless execute permissions are set?&lt;br&gt;
&lt;br&gt;
Finally, this one is driving me nuts: What&apos;s the extra flag at the end of the file for in Terminal? When I check file permissions with ls -al some files show as -rwxr-xr-x+, others show as -rwxr-xr-x@, and some are -rwxr-xr-x with no + or @ appended. Nothing I&apos;ve been able to find online explains what the @ or + flags mean, or why they may be appended to some files but not others. I&apos;ve never seen similar flags on any Linux system I&apos;ve used. Should I even care?</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2008:site.91968</guid>
	<pubDate>Tue, 20 May 2008 15:41:37 -0800</pubDate>
	<category>Apache</category>
	<category>bash</category>
	<category>filepermissions</category>
	<category>OSX</category>
	<category>permissions</category>
	<dc:creator>caution live frogs</dc:creator>
	</item>
	<item>
	<title>Shell scripting or something better?</title>
	<link>http://ask.metafilter.com/91011/Shell%2Dscripting%2Dor%2Dsomething%2Dbetter</link>	
	<description>Faster techniques for grabbing lines of a file and doing text manipulation and arithmetic via shell (or other) scripting? 1. Are there faster ways to grab lines of a text file?&lt;br&gt;
&lt;br&gt;
Currently I use &lt;code&gt;while read line&lt;/code&gt; and &lt;code&gt;sed -n #p filename&lt;/code&gt; in &lt;code&gt;bash&lt;/code&gt; and &lt;code&gt;csh&lt;/code&gt; scripts to grab lines of a file I&apos;m interested in. This seems slow. Are there better (faster) ways to get the line of a file, or to iterate through specified ranges of lines in a file?&lt;br&gt;
&lt;br&gt;
2. Are there faster ways than &lt;code&gt;awk&lt;/code&gt; to grab values in a line?&lt;br&gt;
&lt;br&gt;
Let&apos;s say I have the tab-delimited line:&lt;br&gt;
&lt;br&gt;
&lt;code&gt;abc   123   345   0.52&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
What I&apos;d like to do is get the second and third values, or the fourth value, as quickly as possible. Is there a better way than &lt;code&gt;awk&lt;/code&gt;? Will a perl or other interpreted language script run faster than a shell script for scraping values from a text file?&lt;br&gt;
&lt;br&gt;
3. Arithmetic with &lt;code&gt;bash&lt;/code&gt;?&lt;br&gt;
&lt;br&gt;
I&apos;ve been doing &lt;code&gt;$((${value1}+${value2}))&lt;/code&gt; for integer arithmetic and &lt;code&gt;calc ${value1} / ${value2}&lt;/code&gt; for floating point arithmetic within &lt;code&gt;bash&lt;/code&gt;. Will I gain a performance benefit from switching over my code from &lt;code&gt;bash&lt;/code&gt; to another shell script language, or to another interpreted language entirely?&lt;br&gt;
&lt;br&gt;
Thanks for any and all tips and tricks.</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2008:site.91011</guid>
	<pubDate>Fri, 09 May 2008 14:19:40 -0800</pubDate>
	<category>arithmetic</category>
	<category>bash</category>
	<category>csh</category>
	<category>float</category>
	<category>integer</category>
	<category>perl</category>
	<category>processing</category>
	<category>python</category>
	<category>script</category>
	<category>scripting</category>
	<category>text</category>
	<dc:creator>Blazecock Pileon</dc:creator>
	</item>
	<item>
	<title>Simple Filename Parsing Question</title>
	<link>http://ask.metafilter.com/85683/Simple%2DFilename%2DParsing%2DQuestion</link>	
	<description>Should-be-simple Linux timestamped file parsing question. I have a directory with what is now 10k jpeg files in this format (number of seconds since 1970):&lt;br&gt;
&lt;br&gt;
1202499302.jpg&lt;br&gt;
1202419201.jpg&lt;br&gt;
1202439301.jpg&lt;br&gt;
1202459401.jpg&lt;br&gt;
1202479501.jpg&lt;br&gt;
1202499602.jpg&lt;br&gt;
1202419502.jpg&lt;br&gt;
1202439601.jpg&lt;br&gt;
1202459702.jpg&lt;br&gt;
1202479801.jpg&lt;br&gt;
1202499901.jpg&lt;br&gt;
&lt;br&gt;
I&apos;d like to use a script of some sort to shuffle these images into directories based on month, then day. Note that the &quot;last modified&quot; times on the file system are not necessarily the same as the timestamp in the file name, and I&apos;d like to collate the files with the file name timestamp, not the filesystem timestamp.&lt;br&gt;
&lt;br&gt;
Can anyone suggest a way to do this?&lt;br&gt;
&lt;/timestamp&gt;</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2008:site.85683</guid>
	<pubDate>Sun, 09 Mar 2008 07:33:42 -0800</pubDate>
	<category>bash</category>
	<category>file</category>
	<category>linux</category>
	<category>parsing</category>
	<category>script</category>
	<category>timestamp</category>
	<dc:creator>yellowbkpk</dc:creator>
	</item>
	<item>
	<title>how split a string in bash?</title>
	<link>http://ask.metafilter.com/80862/how%2Dsplit%2Da%2Dstring%2Din%2Dbash</link>	
	<description>using bash, i need to split a variable in two, on whitespace, but with just the first word in one variable, and the rest in the second variable.  this is a one liner with perl.  how in bash? i have a properties file in the format:&lt;br&gt;
&lt;br&gt;
variable   (whitespace)  value&lt;br&gt;
&lt;br&gt;
values can include spaces, variables are always a single word.  e.g.:&lt;br&gt;
&lt;br&gt;
thisvar       contents of this var&lt;br&gt;
&lt;br&gt;
i need to extract &apos;thisvar&apos; and &apos;contents of this var&apos; as two strings.&lt;br&gt;
&lt;br&gt;
in perl i&apos;d do:&lt;br&gt;
&lt;br&gt;
($first, $rest) = split (&apos; &apos;,$source)&lt;br&gt;
&lt;br&gt;
how can i do this in a shell?  (i.e. bash)</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2008:site.80862</guid>
	<pubDate>Sat, 12 Jan 2008 19:21:39 -0800</pubDate>
	<category>bash</category>
	<category>programming</category>
	<category>shell</category>
	<dc:creator>jimjam</dc:creator>
	</item>
	<item>
	<title>How can I insert text into an existing PDF using Ghostscript?</title>
	<link>http://ask.metafilter.com/79284/How%2Dcan%2DI%2Dinsert%2Dtext%2Dinto%2Dan%2Dexisting%2DPDF%2Dusing%2DGhostscript</link>	
	<description>How can I insert text into an existing PDF using Ghostscript? I&apos;m attempting to write a bash script that will take the output of the &quot;tree&quot; command, and insert it into an existing PDF template. The script works, bu I haven&apos;t been able to figure out how to take the output of it and stick it into this template. Does anyone know of a solution that does no use any additional software other than Ghostscript?</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2007:site.79284</guid>
	<pubDate>Fri, 21 Dec 2007 21:25:10 -0800</pubDate>
	<category>BASH</category>
	<category>Ghostscript</category>
	<category>Linux</category>
	<category>PDF</category>
	<dc:creator>jackofsaxons</dc:creator>
	</item>
	<item>
	<title>Remotely starting local X application?</title>
	<link>http://ask.metafilter.com/76470/Remotely%2Dstarting%2Dlocal%2DX%2Dapplication</link>	
	<description>How do I restart an X Windows application running on a remote machine, and have it display on that computer&apos;s locally-attached display? (I &lt;i&gt;do not&lt;/i&gt; want to forward/tunnel it to the machine I&apos;m sitting at.) Two computers, foo and bar. Foo is a machine connected to a big display, but lacking any local controls (keyboard or mouse). Bar is a laptop. Foo normally runs an X Windows application, but sometimes this application crashes.&lt;br&gt;
&lt;br&gt;
How can I, by connecting to foo from bar via SSH, restart an X app running on foo, and have it come back up on foo&apos;s display? All the resources I can find on the net deal with forwarding X connections so that I could display them remotely on bar (which I can do fine), but that&apos;s not what I want. I want to issue the command via SSH, but have the application display itself on the local display. (And once I get it running, I want to close down the SSH connection.)&lt;br&gt;
&lt;br&gt;
I&apos;m sure it has something to do with the DISPLAY variable, but I can&apos;t figure out what to set it as. (I&apos;ve tried setting it to &quot;localhost:0&quot; and &quot;127.0.0.1:0&quot; as well as &quot;:1&quot; on both, but both give &quot;can&apos;t open display&quot; errors.)&lt;br&gt;
&lt;br&gt;
It seems like this ought to be a lot easier than tunneling an X connection, but I&apos;m stumped.&lt;br&gt;
&lt;br&gt;
&lt;small&gt;This is all using Knoppmyth, which is Debian/X11.org-based, with Bash.&lt;/small&gt;</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2007:site.76470</guid>
	<pubDate>Fri, 16 Nov 2007 21:16:09 -0800</pubDate>
	<category>bash</category>
	<category>linux</category>
	<category>mythtv</category>
	<category>networking</category>
	<category>ssh</category>
	<category>x</category>
	<category>xwindows</category>
	<dc:creator>Kadin2048</dc:creator>
	</item>
	<item>
	<title>Bash, I command thee to always...</title>
	<link>http://ask.metafilter.com/74409/Bash%2DI%2Dcommand%2Dthee%2Dto%2Dalways</link>	
	<description>How do I get bash to automagically execute a line or two of code at login? I ssh into various web servers all day long.  They&apos;re helpfully *cough* configured to log me off after a few minutes inactivity, so re-logging in happens a lot.  Then the re-return to the correct working directory.  Where do I put something like &apos;cd ~/foo/bar&apos; to instruct bash to execute that step (and whatever other convenience steps I can think of) automatically at shell login?  I tried just dropping that into ~/.bash_profile, but no dice.  &apos;chmod +x ~/.bash_profile&apos; didn&apos;t make a difference.</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2007:site.74409</guid>
	<pubDate>Mon, 22 Oct 2007 16:27:48 -0800</pubDate>
	<category>bash</category>
	<category>bsd</category>
	<category>cli</category>
	<category>commandline</category>
	<category>console</category>
	<category>linux</category>
	<category>login</category>
	<category>resolved</category>
	<category>screen</category>
	<category>script</category>
	<category>server</category>
	<category>shell</category>
	<category>terminal</category>
	<category>timeout</category>
	<category>unix</category>
	<dc:creator>nakedcodemonkey</dc:creator>
	</item>
	<item>
	<title>Help improve my scripting skills</title>
	<link>http://ask.metafilter.com/70361/Help%2Dimprove%2Dmy%2Dscripting%2Dskills</link>	
	<description>I wrote a shell script for an acquaintance that renames Macs (OS 10.4) based on their existing names. It works well, but I&apos;m convinced my code could be more efficient. Where can I make improvements? First, some background. The old naming scheme was [Building]_[CPU speed]_[Model]_[number]. The length of the names was cumbersome, so they decided to shorten them to [abbreviated building name]-[model]-[A/B][number], where A=1.42GHz and B=1.25GHz. For example, if the old names are&lt;br&gt;
&lt;br&gt;
Berkeley_1.25Ghz_eMac_01&lt;br&gt;
Washington_700MHz_iMac_01&lt;br&gt;
&lt;br&gt;
the new names should be&lt;br&gt;
&lt;br&gt;
berk-emac-B01&lt;br&gt;
wash-imac-01 (they only have 700Mhz iMacs)&lt;br&gt;
&lt;br&gt;
This is the bash script I came up with (with comments), that gets run as root on each computer:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
# get the current computer name&lt;br&gt;
NAME=`scutil --get ComputerName`&lt;br&gt;
&lt;br&gt;
# split the name into its component parts&lt;br&gt;
BLDG=`echo $NAME | awk -F_ &apos;{print $1}&apos;`&lt;br&gt;
CPU=`echo $NAME | awk -F_ &apos;{print $2}&apos;`&lt;br&gt;
MOD=`echo $NAME | awk -F_ &apos;{print $3}&apos;`&lt;br&gt;
NUM=`echo $NAME | awk -F_ &apos;{print $4}&apos;`&lt;br&gt;
&lt;br&gt;
# replace full building name with abbreviation&lt;br&gt;
newBLDG=`echo $BLDG | sed \&lt;br&gt;
    -e &apos;s/Berkeley/berk/&apos; \&lt;br&gt;
    -e &apos;s/Washington/wash/&apos;`&lt;br&gt;
&lt;br&gt;
# make model lowercase&lt;br&gt;
newMOD=`echo $MOD | tr [:upper:] [:lower:]`&lt;br&gt;
&lt;br&gt;
# replace cpu speed with letter (or no letter for 700MHz)&lt;br&gt;
newCPU=`echo $CPU | sed \&lt;br&gt;
    -e &apos;s/1.42GHz/A/&apos; \&lt;br&gt;
    -e &apos;s/1.25GHz/B/&apos; \&lt;br&gt;
    -e &apos;s/700MHz//&apos;`&lt;br&gt;
&lt;br&gt;
# reassemble name from new parts&lt;br&gt;
newNAME=$newBLDG-$newMOD-$newCPU$NUM&lt;br&gt;
&lt;br&gt;
# assign the new name to the computer&lt;br&gt;
scutil --set ComputerName $newNAME&lt;br&gt;
scutil --set LocalHostName $newNAME&lt;/code&gt;</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2007:site.70361</guid>
	<pubDate>Wed, 29 Aug 2007 06:55:53 -0800</pubDate>
	<category>awk</category>
	<category>bash</category>
	<category>script</category>
	<category>sed</category>
	<category>shell</category>
	<dc:creator>pmbuko</dc:creator>
	</item>
	<item>
	<title>Strip me some mp3 urls.</title>
	<link>http://ask.metafilter.com/62318/Strip%2Dme%2Dsome%2Dmp3%2Durls</link>	
	<description>In Linux, what&apos;s the simplest way to take a podcast RSS file as input, and  output a file containing just the URLs of all the MP3s enclosed in the RSS file?  Difficulty: the method must only Bash + GNU tools, Python or Perl, with no non-standard add-on libraries or dependencies required.</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2007:site.62318</guid>
	<pubDate>Thu, 10 May 2007 05:32:14 -0800</pubDate>
	<category>bash</category>
	<category>enclosures</category>
	<category>linux</category>
	<category>mp3</category>
	<category>perl</category>
	<category>podcast</category>
	<category>python</category>
	<category>rss</category>
	<category>xml</category>
	<dc:creator>Jimbob</dc:creator>
	</item>
	<item>
	<title>Help me consolidate thousands of pictures</title>
	<link>http://ask.metafilter.com/55742/Help%2Dme%2Dconsolidate%2Dthousands%2Dof%2Dpictures</link>	
	<description>I have a bunch of directories of pictures across multiple disks.  Many images are duplicated.  Additionally, I had to use some disk recovery software to rescue other images and the filenames changed.  At the moment, I can&apos;t guarantee that all of the filenames are unique.

I&apos;d like to weed out the duplicates and then ultimately consolidate everything into iPhoto.   I&apos;m talking close to 20,000 pictures. I had two backup volumes fail simultaneously.  I was able to recover some pictures from drive A, some from drive B, and not really know what I have in common.  I&apos;m sure there is LOTS of overlap.&lt;br&gt;
&lt;br&gt;
Is there a program (hello perl wizards) that will weed out duplicates by CRC?  I&apos;m sure that through the various recovery procedures, the pictures were given different names.  And I&apos;m not quite sure the naming is unique, so I dont want to just &lt;br&gt;
&lt;br&gt;
&lt;code&gt;find . -name \*.jpg -exec mv {} mynewdirectory \;&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
for fear that I&apos;ll overwrite files.  Plus that wont weed out the dupes.  Any better ideas?</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2007:site.55742</guid>
	<pubDate>Thu, 25 Jan 2007 11:07:07 -0800</pubDate>
	<category>bash</category>
	<category>cli</category>
	<category>ksh</category>
	<category>osx</category>
	<category>photography</category>
	<dc:creator>neilkod</dc:creator>
	</item>
	<item>
	<title>iPod abuse</title>
	<link>http://ask.metafilter.com/53949/iPod%2Dabuse</link>	
	<description>Stop me hitting my iPod! My 4th gen iPod requires frequent slapping to encourage it to unfreeze (try Googling &apos;slap+ipod&apos; to see what I mean). What does this particular &apos;fix&apos; actually do? How do I fix my iPod in a more permanent way? It seems that since this slapping is often successful, there might be single problem that it is fixing? Loose HD connection or something?</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2006:site.53949</guid>
	<pubDate>Thu, 28 Dec 2006 10:35:43 -0800</pubDate>
	<category>4th</category>
	<category>bash</category>
	<category>belt</category>
	<category>frozen</category>
	<category>gen</category>
	<category>hit</category>
	<category>iPod</category>
	<category>pound</category>
	<category>slap</category>
	<category>smack</category>
	<category>strike</category>
	<category>workyoufuckingthing</category>
	<dc:creator>Kiwi</dc:creator>
	</item>
	<item>
	<title>How to get a screen session to work the way I want to?</title>
	<link>http://ask.metafilter.com/50208/How%2Dto%2Dget%2Da%2Dscreen%2Dsession%2Dto%2Dwork%2Dthe%2Dway%2DI%2Dwant%2Dto</link>	
	<description>How do I get my Linux shell to behave the same when I am using screen, as when I am not using it? I connect to my linux servers with Putty, from Windows. These are two different servers, but I have the same annoyance. When I work in the shell (bash) without using screen, and I use &quot;less&quot; or &quot;man&quot; or &quot;vim&quot; or something like that to read a file, and I close that file, the open file remains visible in the window. I just start typing new stuff below it. If I do not use screen, when I close the file, I get returned to the shell window I was using before, and I can see my previous commands.&lt;br&gt;
&lt;br&gt;
Also, when I am not in a screen session, I can use the scrollbars in Putty to scroll up in history. When I am in a screen session, this does not work. I can imagine this is a limitation of screen sessions, but if there is a solution for this, I would like to know as well.&lt;br&gt;
&lt;br&gt;
The latter annoyance is not as important, but the former has been irritating me for a long while now, and I hope there is an easy solution.</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2006:site.50208</guid>
	<pubDate>Sun, 05 Nov 2006 09:17:07 -0800</pubDate>
	<category>annoyance</category>
	<category>bash</category>
	<category>linux</category>
	<category>screen</category>
	<category>shell</category>
	<dc:creator>davar</dc:creator>
	</item>
	<item>
	<title>Changing gnome wallpaper</title>
	<link>http://ask.metafilter.com/47303/Changing%2Dgnome%2Dwallpaper</link>	
	<description>Linux / Ubuntu / Gnome question - how do I tell Gnome &quot;Hey, the jpg you&apos;re using as desktop wallpaper has been updated with a new image.  Go reload it and display the new version?&quot; in a Python or Bash script? I&apos;ve written a little Python script that runs once a day, and downloads the NASA Astronomy Image Of The Day, and saves it to a local file.  Gnome is set up to use this file as my desktop wallpaper.  The problem is, while the script downloads the new image every day, Gnome never checks the file to see if it&apos;s changed, so my wallpaper remains the same unless I restart the computer, or manually change the wallpaper on the Gnome desktop.&lt;br&gt;
&lt;br&gt;
How can I automatically tell Gnome to &quot;reload&quot; the wallpaper jpg?</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2006:site.47303</guid>
	<pubDate>Tue, 26 Sep 2006 03:18:50 -0800</pubDate>
	<category>bash</category>
	<category>desktop</category>
	<category>gnome</category>
	<category>linux</category>
	<category>python</category>
	<category>ubuntu</category>
	<category>wallpaper</category>
	<dc:creator>Jimbob</dc:creator>
	</item>
	<item>
	<title>bash bash bash</title>
	<link>http://ask.metafilter.com/43945/bash%2Dbash%2Dbash</link>	
	<description>Calling all bash/nix gurus.. please help me! I have a list of users that I&apos;m trying to parse and convert into a html-friendly format, surrounding them around &amp;lt;option&amp;gt; tags so I can put them in an HTML select form.&lt;br&gt;
&lt;br&gt;
I&apos;m getting input from /etc/passwd, grepping to find users that are enabled login, cutting and getting the first segment before a colon, and sorting in alphabetical order -- then surrounding the resulting list of login IDs in option tags:&lt;br&gt;
&lt;br&gt;
&lt;tt&gt;cat /etc/passwd | egrep &quot;\[N?U&quot; | cut -d : -f 1 | sort | sed -n &apos;s/.*/&amp;lt;option value=\&quot;&amp;amp;\&quot;&amp;gt;&amp;amp;&amp;lt;\/option&amp;gt;&lt;/tt&gt;&lt;br&gt;
&lt;br&gt;
Which yields:&lt;br&gt;
&amp;lt;option value=&quot;loginID1&quot;\&amp;gt;loginID1&amp;lt;/option\&amp;gt;&lt;br&gt;
,etc.&lt;br&gt;
&lt;br&gt;
That&apos;s all fine, not a problem. &lt;b&gt;But -- &lt;/b&gt; now I want to run each ID through &apos;lookup&apos; and grep the name out, and then insert between the option tags, where the second ampersand is, like this:&lt;br&gt;
&lt;br&gt;
&amp;lt;option value=&quot;loginID1&quot;&amp;gt;Firstname Lastname1&amp;lt;/option&amp;gt;&lt;br&gt;
&lt;br&gt;
Assuming that &lt;tt&gt;lookup loginID1&lt;/tt&gt; returns &lt;tt&gt;Firstname Lastname 1&lt;/tt&gt;, how can I do this? It seems that I need to keep the original values of the /etc/password - parsed values while also running them through lookup. Is there any way I can do this in one line, without having to resort to loops/arrays in bash? Or will an in-line Perl script help? &lt;br&gt;
&lt;br&gt;
Thanks!</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2006:site.43945</guid>
	<pubDate>Tue, 08 Aug 2006 13:03:24 -0800</pubDate>
	<category>bash</category>
	<category>nix</category>
	<category>shellscript</category>
	<dc:creator>provolot</dc:creator>
	</item>
	<item>
	<title>No more shell games!</title>
	<link>http://ask.metafilter.com/39266/No%2Dmore%2Dshell%2Dgames</link>	
	<description>*nix shell &quot;best practices&quot; anyone? Over the years I&apos;ve been writing more and more shell scripts (bash, ksh, perl, expect) and they&apos;ve been getting more and more complexe.  I haven&apos;t been able to find a comprehensive list of best practices for shell programming although I have learned a lot by looking at other people&apos;s scripts (thank you sanity checks!)  I&apos;m looking for links or your own best practices.  &lt;br&gt;
&lt;br&gt;
Here&apos;s an example:&lt;br&gt;
&lt;br&gt;
&lt;small&gt;Use &lt;code&gt;${FOO}&lt;/code&gt; instead of &lt;code&gt;$FOO&lt;/code&gt; so that the variable is more likely to be interpreted when concatenated in a string and use &lt;code&gt;&amp;gt;&amp;gt; &quot;${FOO}&quot;&lt;/code&gt; instead of &lt;code&gt;&amp;gt;&amp;gt; ${FOO}&lt;/code&gt; in case &lt;code&gt;${FOO}&lt;/code&gt; has spaces in it.&lt;/small&gt;</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2006:site.39266</guid>
	<pubDate>Wed, 31 May 2006 17:02:01 -0800</pubDate>
	<category>aix</category>
	<category>bash</category>
	<category>korn</category>
	<category>ksh</category>
	<category>linux</category>
	<category>perl</category>
	<category>python</category>
	<category>rhino</category>
	<category>sh</category>
	<category>shell</category>
	<category>unix</category>
	<dc:creator>furtive</dc:creator>
	</item>
	<item>
	<title>Python - Shell Environment</title>
	<link>http://ask.metafilter.com/35918/Python%2DShell%2DEnvironment</link>	
	<description>Is there a way to set an environment variable in the unix shell from a python script? Can I set a variable in the shell that executes that same script? For that matter, is there a way for any script to do this? In other words, I am trying to set up a nice environment in my unix shell (potentially bash or tcsh), and I need to set up some custom paths. I would like to do this from a script.&lt;br&gt;
&lt;br&gt;
It seems that,&lt;br&gt;
 &lt;br&gt;
MY_PATH = os.getenv(&apos;PATH&apos;, &apos;Error&apos;)&lt;br&gt;
os.environ[&quot;PATH&quot;] = MY_PATH + &apos;:&apos; + install_path + &apos;/bin&apos;&lt;br&gt;
&lt;br&gt;
sets $PATH in some subshell spawned by python, and it doesn&apos;t update the environment of the shell that executes the python script. &lt;br&gt;
&lt;br&gt;
I had this problem in trying to write a bash script as well.</description>
	<guid isPermaLink="false">tag:ask.metafilter.com,2006:site.35918</guid>
	<pubDate>Fri, 07 Apr 2006 12:17:12 -0800</pubDate>
	<category>bash</category>
	<category>environment</category>
	<category>python</category>
	<category>tcsh</category>
	<category>variables</category>
	<dc:creator>kuatto</dc:creator>
	</item>
	
	</channel>
</rss>

