将多行代码传递给 wsadmin.sh?
Passing multiple lines of code to wsadmin.sh?
我想将几行代码传递给 WebSphere 配置文件。
这是我的尝试:
# ./wsadmin.sh -lang jython -c 'print("Hello")
> print("World!")'
这打印出响应:
WAS7209I: Connected to process"<my profile name>" on node <node name> using SOAP connector; The type of process is: UnManagedProcess
Hello
请注意,它似乎只是忽略了同一行代码。
当我在 Python 中尝试同样的事情时,它工作正常:
# python -c 'print("Hello")
> print("World!")
打印:
Hello
World!
我在 CentOS 7 上使用 WebSphere 8.5 版。
注意:在得到 Ram Vennam 的回答后,我在超级用户上发布了一个不同倾向的相关问题:https://superuser.com/q/939746/240375 - 这是我真正得到答案的地方。
您可以使用分号:
./wsadmin.sh -lang jython -c 'print("Hello");print("World!")'
或者,可以使用 –f 选项和 wsadmin 将脚本文件作为输入。
$wsadmin.sh-fyour_script_file
Edward's Answer on SuperUser and 两者大致在同一时间提供了相同的解决方案,但当我要求他们发布时,他们都没有将其作为答案发布在这里,所以我在这里发布,所以我有一个正确的答案接受。
$ ./wsadmin.sh -lang jython -f <(echo 'print("Hello")
> print("World")')
完美运行。它允许您将行 returns 放入。它尊重缩进,因此您可以使用 for 循环并定义函数和 类 以及其他需要缩进行的所有内容。
一个额外的好处,我将分享如何在代码中转义单引号:
'\''
第一个引号结束前面的字符串。 \'
放入单引号文字。最后一个引号开始下一个字符串。 Bash 自动将三者连接在一起形成一个连续的字符串,中间有一个单引号。所以如果我想使用单引号而不是上面的双引号,它看起来像这样:
$ ./wsadmin.sh -lang jython -f <(echo 'print('\''Hello'\'')
> print('\''World'\'')')
我想将几行代码传递给 WebSphere 配置文件。
这是我的尝试:
# ./wsadmin.sh -lang jython -c 'print("Hello")
> print("World!")'
这打印出响应:
WAS7209I: Connected to process"<my profile name>" on node <node name> using SOAP connector; The type of process is: UnManagedProcess
Hello
请注意,它似乎只是忽略了同一行代码。
当我在 Python 中尝试同样的事情时,它工作正常:
# python -c 'print("Hello")
> print("World!")
打印:
Hello
World!
我在 CentOS 7 上使用 WebSphere 8.5 版。
注意:在得到 Ram Vennam 的回答后,我在超级用户上发布了一个不同倾向的相关问题:https://superuser.com/q/939746/240375 - 这是我真正得到答案的地方。
您可以使用分号:
./wsadmin.sh -lang jython -c 'print("Hello");print("World!")'
或者,可以使用 –f 选项和 wsadmin 将脚本文件作为输入。
$wsadmin.sh-fyour_script_file
Edward's Answer on SuperUser and
$ ./wsadmin.sh -lang jython -f <(echo 'print("Hello")
> print("World")')
完美运行。它允许您将行 returns 放入。它尊重缩进,因此您可以使用 for 循环并定义函数和 类 以及其他需要缩进行的所有内容。
一个额外的好处,我将分享如何在代码中转义单引号:
'\''
第一个引号结束前面的字符串。 \'
放入单引号文字。最后一个引号开始下一个字符串。 Bash 自动将三者连接在一起形成一个连续的字符串,中间有一个单引号。所以如果我想使用单引号而不是上面的双引号,它看起来像这样:
$ ./wsadmin.sh -lang jython -f <(echo 'print('\''Hello'\'')
> print('\''World'\'')')