文章目录

  • 1.首先要下载Git
  • 2.使用IDEA安装BashSupport插件
  • 3.相关设置
  • 4.解决乱码问题
  • 5.shell脚本运行



IDEA本身不能运行shell脚本,需要借助插件实现,下面我来详细讲解一下步骤

1.首先要下载Git

Git下载地址 进入后点击下载安装包

shell脚本打开redis操作 shell脚本 ide_shell脚本


下载完成,点击运行安装包,全都默认选项即可,就是一直点next,不过安装路径要自己选择熟悉的地方,比如就是安装在D盘的,如下图

shell脚本打开redis操作 shell脚本 ide_intellij idea_02

2.使用IDEA安装BashSupport插件

步骤:File–>Settings–>搜素框搜索Plugins–>Marketplcae

shell脚本打开redis操作 shell脚本 ide_乱码问题_03


搜索插件BashSupport–>点击INSTALL

shell脚本打开redis操作 shell脚本 ide_shell脚本_04

3.相关设置

打开设置,按图中操作进行设置,设置完成后记得APPLY–>ok

shell脚本打开redis操作 shell脚本 ide_乱码问题_05


然后进行运行配置,跟配置Tomcat差不多

shell脚本打开redis操作 shell脚本 ide_shell_06


点击+找到Bash

shell脚本打开redis操作 shell脚本 ide_shell脚本打开redis操作_07


然后进行相关配置(这一步每个新的shell脚本都需要重新配置,我没找到解决办法)

你可以在编写完代码后直接运行,系统会提示你配置,你点开把这个Use project interpreter 勾选起就行了

shell脚本打开redis操作 shell脚本 ide_intellij idea_08


完成后apply–>ok

4.解决乱码问题

有时候运行会出现乱码,需要进行配置

如下图:

shell脚本打开redis操作 shell脚本 ide_intellij idea_09


将此代码添加到最后一行,如图所示

-Dfile.encoding=UTF-8

shell脚本打开redis操作 shell脚本 ide_shell脚本打开redis操作_10


至此,设置基本完成,需要进行重启IDEA,不然不会生效

5.shell脚本运行

就像创建java类一样,创建一个包,包下面创建shell脚本,如图所示

shell脚本打开redis操作 shell脚本 ide_shell_11


shell脚本打开redis操作 shell脚本 ide_shell_12


刚创建完成,系统会提示你,你点击就可以了

shell脚本打开redis操作 shell脚本 ide_shell_13


到这里,就可以愉快的编程了

shell脚本打开redis操作 shell脚本 ide_intellij idea_14


下面是测试代码

#!/usr/bin/env bash
while [ "1" = "1" ]
do
    echo -n "请输入车的价钱:"
    read input
        if [ $input -le 0 ]
        then
        echo '输入错误'
        elif [ $input -ge 30 ]
        then
        echo 'A级车'
        elif [ $input -ge 20 ]
        then
        echo 'B级车'
        elif [ $input -ge 10 ]
        then
        echo 'C级车'
        else [ $input -lt 10  ]
        echo '两厢车'
        fi
done

右击鼠标–>运行

shell脚本打开redis操作 shell脚本 ide_intellij idea_15


运行结果截图:

shell脚本打开redis操作 shell脚本 ide_intellij idea_16


以上就是详细的过程,实操有效!!!