小编iam*_*est的帖子

使用 echo 时,tee 和 >> 之间有什么区别吗?

这样做有什么区别:

echo "hahaha" >> file1
Run Code Online (Sandbox Code Playgroud)

echo "hahaha" |tee -a file1
Run Code Online (Sandbox Code Playgroud)

?

是的,我注意到我什至无法写入受保护的文件sudo echo,但如果我可以sudo tee。谢谢。

io-redirection tee stdout

5
推荐指数
2
解决办法
5303
查看次数

wc -c 给我一个额外的字符数

因此,我制作了一个将用户添加到系统的脚本,并希望将用户名的长度强制为 8 个字符或以下。

#!/bin/bash
# Only works if you're root

for ((a=1;a>0;a)); do
 if [[ "$UID" -eq 0 ]]; then
  echo "Quit this shit anytime by pressing CTRL + C"
  read -p 'Enter one usernames: ' USERNAME
  nrchar=$(echo ${USERNAME} | wc -c)
  echo $nrchar
  spcount=$(echo ${USERNAME} | tr -cd ' ' | wc -c)
  echo $spcount
  if [[ "${nrchar}" -ge 8 ]]; then
    echo "You may not have more than 8 characters in the username"
   elif [[ "${spcount}" -gt 0 …
Run Code Online (Sandbox Code Playgroud)

shell grep scripting bash wc

4
推荐指数
1
解决办法
3479
查看次数

sha1sum 函数如何为您提供唯一的哈希值?

我读到使用该sha1sum命令将运行 SHA-1 算法并为您提供“唯一”结果,但这怎么可能?

sha1sum 为您提供 40 个字符的哈希值,如下所示:

e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e
Run Code Online (Sandbox Code Playgroud)

这是 40 个字符长,并且有十六进制字符,因此哈希最多可以有 16 40 种组合。

这应该意味着,对于任何两个随机文件,有一个很小的机会,他们的哈希和将是完全一样的,对不对?

sha1sum

4
推荐指数
1
解决办法
1056
查看次数

标签 统计

bash ×1

grep ×1

io-redirection ×1

scripting ×1

sha1sum ×1

shell ×1

stdout ×1

tee ×1

wc ×1