Bash Commands - chmod # Invoking script

本文介绍如何通过chmod命令设置Bash脚本文件的执行权限,并解释了如何使用不同的权限级别。此外,还提供了创建并运行一个简单Bash脚本的例子,并说明了脚本头部的sha-bang行的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. Invoke

Having written the script, you can invoke it by bash scriptname

Much more convenient is to make the script itself directly executable with a chmod.

Either:

$ chmod 555 scriptname            (gives everyone read/execute permission)  or

$ chmod +rx scriptname             (gives everyone read/execute permission)


$ chmod u+rx scriptname            (gives only the script owner read/execute permission)

2. Test

Having made the script executable, you may now test it by

./scriptname


For example:

$ cat >test_chmod << "EOF"                # Create a (script) file named test_chmod.

> #!/bin/bash                                              # the "sha-bang" line. Indicate calling command interpreter.

> echo "Hello,bash world!"                    # Write a script command.

> EOF                                                           # End the file.

$ chmod 555 test_chmod                      # Invoke the script file, gives everyone read/execute permission.

$ ./test_chmod                                          # test it!

Hello,bash world!                                      # The script file was run.

3. "sha-bang" line

#!/bin/sh
#!/bin/bash
#!/usr/bin/perl
#!/usr/bin/tcl
#!/bin/sed -f
#!/bin/awk -f

Each of the above script header lines calls a different command interpreter, be it /bin/sh, the default shell
(bash in a Linux system) or otherwise.

Note: $chmod 4755 filename                   # Give filename root permission.

[weblogic@hqtrtgscnyapp01 rtgscny_domain]$ ./bin/stopWebLogic.sh Stopping Weblogic Server... [0.005s][warning][cds] Archived non-system classes are disabled because the java.system.class.loader property is specified (value = "com.oracle.classloader.weblogic.LaunchClassLoader"). To use archived non-system classes, this property must not be set Initializing WebLogic Scripting Tool (WLST) ... Welcome to WebLogic Server Administration Scripting Shell Type help() for help on available commands No stack trace available. Traceback (most recent call last): File "/opt/Oracle/Weblogic/fmw141200/user_projects/domains/rtgscny_domain/shutdown-AdminServer.py", line 3, in <module> connect( url=&#39;t3s://hqtrtgscnyapp01:9002&#39;, adminServerName=&#39;AdminServer&#39;) File "<iostream>", line 19, in connect File "<iostream>", line 586, in raiseWLSTException __main__.WLSTException: Error occurred while performing connect : "No valid username/password or userConfigFile/userKeyFile provided" Problem invoking WLST - Traceback (most recent call last): File "/opt/Oracle/Weblogic/fmw141200/user_projects/domains/rtgscny_domain/shutdown-AdminServer.py", line 3, in <module> connect( url=&#39;t3s://hqtrtgscnyapp01:9002&#39;, adminServerName=&#39;AdminServer&#39;) File "<iostream>", line 19, in connect File "<iostream>", line 586, in raiseWLSTException __main__.WLSTException: Error occurred while performing connect : "No valid username/password or userConfigFile/userKeyFile provided" Done Stopping Derby Server... Derby server stopped. shutDownStatus=1 解析报错
07-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值