2010-12-10 98 views
0

我創建的文件:如何將文件製作成shell腳本並運行它?

tinymce_compressor.sh 
$chmod +x tinymce_compressor.sh 
$ tinymce_compressor 
-bash: tinymce_compressor: command not found 

我怎樣才能在終端運行這個shell腳本?

以下是完整的腳本:

#!/bin/sh 
# Tinymce compressor shell script 
# 
# This program is free software; you can redistribute it and/or modify 
# it under the terms of the GNU General Public License as published by 
# the Free Software Foundation; version 2 of the License. 
# 
# 
# This program is distributed in the hope that it will be useful, 
# but WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
# GNU General Public License for more details. 
#   
# (C) Copyright 2010 Gabor Vitez 
# 
# 
# Concatenates the tinymce components into a single static file 
# Can be used with any web server which can serve static files 
# Note you have to re-run this script every time you upgrade tinymce, 
# or change the required modules 
# 
# Usage: upon every invocation, the scipt will create a new 
# "tinymceappended.js" file, which contains the requested components 
# 
# In your html pages you have to change 
# 
# <script type="text/javascript" src="<your installation path>/tiny_mce/tiny_mce.js"></script> 
# 
# to 
# 
# <script type="text/javascript" src="<your compressed tinymce url>/tinymceappended.js"> </script> 
# 


#config section 
#where does tinymce live in the filesystem? 
BASE="/Users/xxxx/Sites/cline/public/javascripts/tiny_mce/" 
#under which URLs do the original tinymce components show up? 
URLBASE="/tinymce" 
#just as in the javascript config section 
THEMES="advanced" 
PLUGINS="safari spellchecker pagebreak style layer save advhr advimage advlink emotions iespell inlinepopups insertdatetime preview media searchreplace contextmenu paste directionality fullscreen noneditable visualchars nonbreaking xhtmlxtras" 
LANGUAGES="en" 
#end config section 

(
LOADED="" 
cd $BASE || exit 1 
#cat tiny_mce.js 
sed "s/tinymce._init();/tinymce.baseURL='\/tinymce';tinymce._init();/"<tiny_mce.js 
#echo "tinyMCE_GZ.start();" 
#cat tiny_mce_popup.js && LOADED="$LOADED $URLBASE/tiny_mce_popup.js" 
for lang in $LANGUAGES 
     do 
       cat langs/$lang.js && LOADED="$LOADED $URLBASE/langs/$lang.js" 
     done 
for theme in $THEMES 
     do 
       cat themes/$theme/editor_template.js && LOADED="$LOADED $URLBASE/themes/$theme/editor_template.js" 
       for lang in $LANGUAGES 
         do 
           cat themes/$theme/langs/$lang.js && LOADED="$LOADED $URLBASE/themes/$theme/langs/$lang.js" 
         done 

     done 

for plugin in $PLUGINS 
     do 
       cat plugins/$plugin/editor_plugin.js && LOADED="$LOADED $URLBASE/plugins/$plugin/editor_plugin.js" 
       for lang in $LANGUAGES 
         do 
           cat plugins/$plugin/langs/$lang.js && LOADED="$LOADED $URLBASE/plugins/$plugin/langs/$lang.js" 
         done 

     done 
echo 
#echo $LOADED >&2 
for i in $LOADED 
     do 
       echo "tinymce.ScriptLoader.markDone(tinyMCE.baseURI.toAbsolute(\"$i\"));" 
     done 
#echo "tinyMCE_GZ.end();" 
) >tinymceappended.js 

感謝

+0

也許./tinymce_compressor.sh?但我不確定... – BlackBear 2010-12-10 20:02:33

+0

我對這個話題甚至在這個話題上徘徊不前;它適用於[Unix和Linux](http://unix.stackexchange.com/)和[SU](http://superuser.com/) – 2010-12-10 20:04:33

回答

2

你已經成功了,只需要調用

$ ./tinymce_compressor.sh 

看來你來自的Windows,其中的可執行文件可以不帶擴展名被調用,而當前目錄總是在PATH

1

默認情況下,當前目錄不是路徑上;你需要指定腳本是在當前文件夾(.):

./tinymce_compressor.sh 
2

腳本是在當前目錄中,但是這是不是在你的路徑(這是什麼外殼使用,試圖找到命令運行)默認情況下。所以,

./tinymce_compressor.sh 

應該做的伎倆。有關命令搜索路徑的更多信息,以及爲什麼在路徑中包含當前目錄(又名「。」)可能不是一個好主意,請參閱Unix常見問題列表中的「What's wrong with having '.' in your $PATH ? 」。