如何将文件转换为shell脚本并运行它?

时间:2010-12-10 19:59:57

标签: 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

由于

3 个答案:

答案 0 :(得分:2)

默认情况下,脚本位于当前目录中,但不在您的路径中(这是shell用来尝试查找要运行的命令的内容)。所以,

./tinymce_compressor.sh

应该做的伎俩。有关命令搜索路径的更多信息,以及为什么在路径中包含当前目录(也称为“。”)可能不是一个好主意,请参阅Unix常见问题列表中的“What's wrong with having '.' in your $PATH ? ”。

答案 1 :(得分:2)

你已经成功,只需致电

$ ./tinymce_compressor.sh

您似乎来自Windows,可以在没有扩展名的情况下调用可执行文件,当前目录始终位于PATH

答案 2 :(得分:1)

默认情况下,当前目录不在路径上;您需要指定脚本位于当前文件夹(.)中:

./tinymce_compressor.sh