“-”和value=${variable:+(-)init_value}

今天在《ABS》上看到下面这样的命令:
(cd /source/directory && tar cf - .) | (cd /dest/directory && tar xpvf -)
1. 网上查了一下 tar cf应该等价于tar -cf,因为cf是tar命令的option。
2. cf后面的-是什么意思呢?
1)书上的解释如下: The 'c' option 'tar' archiving command creates a new archive,  the 'f' (file) option, followed by '-' designates the target file as stdout , and do it in current directory tree ('.').(意思是说:归档命令tar的选项用于创建一个新的文档,f -表示目标文件是stdout,.表示在当前文件夹中做上面所说的事
-其他意思:
1) Note that in this context the "-" is not itself a Bash operator, but rather an option recognized by certain  UNIX utilities that write to  stdout , such as tar, cat, etc.
2) Where a filename is expected, - redirects output to  stdout (sometimes seen with tar cf), or accepts input from stdin , rather than from a file. This is a method of using a file-oriented utility as a  filter in a pipe.
-重定向输出到stdout例子(cd /source/directory && tar cf - .) | (cd /dest/directory &&  tar xpvf -)
-从stdin接收输入:cat -

value=${variable:-init_value}
这个命令的意思是如果variable没有定义,那么value=init_value,否则value=variable
iubuntu@ubuntu:~/a$ unset variable
iubuntu@ubuntu:~/a$ value=${variable:-123}
iubuntu@ubuntu:~/a$ echo $value
123
iubuntu@ubuntu:~/a$ variable=1
iubuntu@ubuntu:~/a$ value=${variable:-123}
iubuntu@ubuntu:~/a$ echo $value
1
iubuntu@ubuntu:~/a$ 

value=${variable:+init_value}
这个命令的意思是如果variable定义了,那么value=init_value,否则为空
iubuntu@ubuntu:~/a$ unset variable
iubuntu@ubuntu:~/a$ value=${variable:+123}
iubuntu@ubuntu:~/a$ echo $value

iubuntu@ubuntu:~/a$ variable=1
iubuntu@ubuntu:~/a$ value=${variable:+123}
iubuntu@ubuntu:~/a$ echo $value
123
iubuntu@ubuntu:~/a$ 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是上题的代码:def infix_to_postfix(expression): precedence = {'!': 3, '&': 2, '|': 1, '(': 0} op_stack = [] postfix_list = [] token_list = expression.split() for token in token_list: if token.isalnum(): postfix_list.append(token) elif token == '(': op_stack.append(token) elif token == ')': top_token = op_stack.pop() while top_token != '(': postfix_list.append(top_token) top_token = op_stack.pop() else: # operator while op_stack and precedence[op_stack[-1]] >= precedence[token]: postfix_list.append(op_stack.pop()) op_stack.append(token) while op_stack: postfix_list.append(op_stack.pop()) return ' '.join(postfix_list) class Node: def __init__(self, value): self.value = value self.left_child = None self.right_child = None def build_expression_tree(postfix_expr): operator_stack = [] token_list = postfix_expr.split() for token in token_list: if token.isalnum(): node = Node(token) operator_stack.append(node) else: right_node = operator_stack.pop() left_node = operator_stack.pop() node = Node(token) node.left_child = left_node node.right_child = right_node operator_stack.append(node) return operator_stack.pop() def evaluate_expression_tree(node, variable_values): if node.value.isalnum(): return variable_values[node.value] else: left_value = evaluate_expression_tree(node.left_child, variable_values) right_value = evaluate_expression_tree(node.right_child, variable_values) if node.value == '!': return not left_value elif node.value == '&': return left_value and right_value elif node.value == '|': return left_value or right_value expression = "!a & (b | c)" postfix_expression = infix_to_postfix(expression) expression_tree = build_expression_tree(postfix_expression) variable_values = {'a': True, 'b': False, 'c': True} result = evaluate_expression_tree(expression_tree, variable_values) print(result)
最新发布
06-12

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值