I got this script ~/bin/align-tables from emacs stackexchange#!/bin/sh# -*- mode: shell-script -*-## tangle files with org-mode#DIR=`pwd`FILES=# wrap each argument in the code required to call tangle on itfor i in $@; doFILES=$FILES \$i\doneemacs -Q --batch \--eval (progn     (require 'org)(require 'org-table)     (mapc (lambda (file)            (find-file (expand-file-name file \$DIR\))            (org-table-map-tables 'org-table-align)            (write-file file nil)            (kill-buffer)) '($FILES)))I want to apply this script to every .org file in the directory ~/foo. If my working directory is /foo, then issuing $ align-tables *.org works perfectly. However, if I'm in a different directory, issuing $ align-tables ~/foo/*.org gives the error Opening output file: no such file or directory, ~/foo/foo/#bar.org#Since the target directory is listed twice in the error message, I'm assuming the problem is the line DIR='pwd' in the script but I'm not sure how to go about modifying the script.My motivation is that I'm writing a perl program that applies align-tables to many different directories.Any ideas how I can get my script to cooperate?
Why can't I apply this script to files not in my current directory?
bash;shell script;files;emacs