简体   繁体   English

如何在AIX服务器中运行在shell脚本中创建的功能?

[英]How to run a function created in the shell script in an AIX server?

I had created a shell script in a linux machine, it is executing fine in that machine as well as in other linux machine but when I am running the same script in an AIX machine it is not working. 我已经在linux机器上创建了一个shell脚本,该脚本在该机器以及其他linux机器上都能正常运行,但是当我在AIX机器上运行相同的脚本时,它无法正常工作。

For ex- script1 对于脚本1

print "Hello"
a()
{
 print "Welcome"
}

b()
{
 print "Bye"
}

a
b

While executing this script in a linux machine the output is 在Linux机器上执行此脚本时,输出为

Hello
Welcome
Bye

But while executing it in an AIX machine the output is 但是在AIX机器上执行它时,输出是

Hello

I think it is not calling the function a and b in the AIX machine. 我认为它没有在AIX机器中调用函数ab So can anybody give me solution to run the script in both Linux and Aix machine. 所以任何人都可以给我解决方案在Linux和Aix机器上运行脚本。

-try to define function without paranthesis, eg: -尝试在没有括号的情况下定义函数,例如:

function a { print "Welcome" } 功能{打印“欢迎”}

-don't forget to define shell - #!/bin/sh -不要忘记定义shell-#!/ bin / sh

-perhaps try to use another shell implementations (ksh, bash, ...) -可能尝试使用其他Shell实现(ksh,bash等)

-just in case, I saw somewhere that on AIX you can't write both, opening and closing curly braces on the same line { } -以防万一,我看到在AIX上的某处您不能同时在同一行{}上打开和关闭大括号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM