如何循环查看输入文本文件中的Bash文件名列表,以及每个文件名目录中的grep文件(查看文件名是否包含在文件中),并输出到任何文件中未找到的所有文件名的文本?
#!/bin/sh
# This script will be used to output any unreferenced bash files
# included in the WebAMS Project
# Read file path of bash files and file name input
SEARCH_DIR=$(awk -F "=" '/Bash Dir/ {print $2}&
我知道'-z‘检查变量是否为空。但是如何检查变量是否为空。我试过使用“!-z”和“-!Z”,但它不起作用。我用得对吗?
echo "Choose any three player code from above menu. [Case sensitive data]"
read p1 p2 p3 p4
echo ""
if [ -z "$p4" ] #run only if the p4 is empty
then
我希望如果是这样的话,"run p4是空的,p3不是空的。
我不为$pass_tc11设置任何值;因此它在回显时返回null。如何在if子句中进行比较?
这是我的密码。我不想“嗨”被打印.
-bash-3.00$ echo $pass_tc11
-bash-3.00$ if [ "pass_tc11" != "" ]; then
> echo "hi"
> fi
hi
-bash-3.00$
我试图验证用户输入的子域是否有效,但是不管我传入什么,它都是无效的。我知道regex是可以的,所以问题是我的"if“逻辑,但是我对shell/bash还不熟悉。
#!/bin/bash
#
echo Enter the subdomain\'s name to configure.
read SUBDOMAIN
if [[ ! $SUBDOMAIN =~ [A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])? ]]; then
echo "$SUBDOMAIN is not a valid domain"
fi
示
我有一部分代码是我最初无法使用的:
with open ("Names.txt" , "r+") as f:
f.seek(0)
if f.read() == " ":
print("No text")
else:
print("Got text")
它应该检查文本文件是否包含任何文本。
然而,当我运行这段代码时,它总是返回"Got“,即使文件是空的。
我找到了一个让它工作的方法:
with open ("Names.txt" ,
我无法检查从REST返回的列表的状态是否为空,数据以以下格式["IOC","Mycompany","Test"]返回
Test.save($scope.Data,
function(data){
//if(data==null) not working
if(data[0]==null)//not working too
{
考虑一下这个简单的函数
def foo(l=[]):
if not l: print "List is empty"
else : print "List is not empty"
现在让我们打电话给福
x=[]
foo(x)
#List is empty
foo('')
#List is empty
但是如果x='‘列表不是空的!
x=['']
foo(x)
#List is not empty
问题-
为什么不认为空值列表是空的?(在变量的情况下,它被认为是空的。)
X=‘如果x:打印’不空!‘其
# touch $
# gzip $
# gzip --test $.gz
# echo $?
0
# OUT=$(gzip --test $.gz)
# echo $OUT
# if [ -z $OUT ] ; then echo $ ; fi
26521
# if [ -n $OUT ] ; then echo $ ; fi
26521
#
来自bash(1)
-z string True if the length of string is zero. string -n string True if the length of s