我正在写一个.ps1 PowerShell脚本,我想知道如何找到用户传递的参数数量.例如,我需要我的程序来处理多个文件中的字符串检查.所以用户应该能够输入
./Script "a" ex1.txt
要么
./Script "a" ex1.txt ex2.txt
我知道在Bash中我们可以使用$#
,但是我如何检查PowerShell?
我试图不寻找值2,但是"不应该发生"会显示而不是其他,"确定".
If Not InStr("1, 2, 3", "2") Then
MsgBox ("shouldn't happen")
Else
MsgBox ("ok")
End If
Run Code Online (Sandbox Code Playgroud)
我们知道值在字符串中.但由于某种原因,"不"不起作用.有谁知道为什么?
我试图在脚本中修改我的linux机器上的某个文件.该文件是/etc/pam.d/login文件.问题是文件的内容是,
# Prints the message of the day upon succesful login.
# (Replaces the `MOTD_FILE' option in login.defs)
# This includes a dynamically generated part from /run/motd.dynamic
# and a static (admin-editable) part from /etc/motd.
session optional pam_motd.so motd=/run/motd.dynamic noupdate
session optional pam_motd.so
Run Code Online (Sandbox Code Playgroud)
我需要注释掉这个文件中的第二个会话行,但是当我去字符串匹配时,结果如下(我正在使用SED为那些感兴趣的人这样做).
# Prints the message of the day upon succesful login.
# (Replaces the `MOTD_FILE' option in login.defs)
# This includes a dynamically generated part from /run/motd.dynamic
# and a static (admin-editable) part from /etc/motd.
#session optional …
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法从文本框中取值并将其转换为8位数的基数2.
因此,如果他们输入文本框2,它将响应00000010.或者如果他们键入255 11111111等...
有任何方法可以做到这一点.
Dim prVal As Integer
prVal = PrefixTxt.Text
Run Code Online (Sandbox Code Playgroud) 创建一个包含大量测试用例的电子表格,最后表示通过或失败.
现在所有的值都是"通过"或"失败".我需要能够有一个条件,我可以像数字一样输入.如果它高于5我需要它返回一个通行证.如果它低于5我需要它返回一个假.任何解决方案?
所以我需要找到某个文件中单词数量的字数统计
所以在我的代码中我有
grep -c "word" file
Run Code Online (Sandbox Code Playgroud)
(输出我们在文件中看到的实例数量)
但有什么方法可以将其存储到变量中吗?
我试过
a = grep -c "word" file
Run Code Online (Sandbox Code Playgroud)
进而echo $a
也
$a = grep -c "word file
Run Code Online (Sandbox Code Playgroud)
我该怎么办呢?
我有一个问题.我需要首先验证python脚本是否至少有2个变量,然后检查是否有"-v"选项作为第一个参数.我的代码不断抛出索引超出范围异常
import sys
if len(sys.argv) >= 2:
if sys.argv[1]=='-v':
print('verbose option chosen')
else:
print('verbose option not chosen')
else:
print('not enough variables, try again')
Run Code Online (Sandbox Code Playgroud) bash ×2
excel ×2
if-statement ×2
arguments ×1
conditional ×1
contains ×1
formatting ×1
grep ×1
linux ×1
powershell ×1
python ×1
regex ×1
replace ×1
scripting ×1
sed ×1
string ×1
vb.net ×1
vba ×1
winforms ×1