在Python中我使用:
repr('test')
Run Code Online (Sandbox Code Playgroud)
获取输出:
"'test'"
Run Code Online (Sandbox Code Playgroud)
我想做同样的事情,但是在 shell 中能够将该值存储在变量中。我能怎么做?
例如:如果我执行命令:
echo $test
Run Code Online (Sandbox Code Playgroud)
我得到输出:
ghjghj "' bhj ""'' bjhv "''hjuhd
Run Code Online (Sandbox Code Playgroud)
在 shell 中我想这样做:
test=repr(repr($test))
Run Code Online (Sandbox Code Playgroud) 以前的代码:
total=`ls -Rp rootfs | wc -l`
count=0
Run Code Online (Sandbox Code Playgroud)
当我为变量分配一个简单的加法时:
sudo find rootfs -exec cp -d -- "{}" "/media/$USER/{}" 2> /dev/null \; -exec sync \; -exec count=$((count+1)) \; -exec echo -en "\rcopiati: $count/$total" \;
Run Code Online (Sandbox Code Playgroud)
我得到:
find: ‘count=1’: No such file or directory
Run Code Online (Sandbox Code Playgroud)
同样当我执行:
sudo find rootfs -exec cp -d -- "{}" "/media/$USER/{}" 2> /dev/null \; -exec sync \; -exec count=1 \; -exec echo -en "\rcopiati: $count/$total" \;
Run Code Online (Sandbox Code Playgroud)
我犯了同样的错误。为什么?
对于复制的每个文件,我想要计数器:1/13444,即更新为 2/13444、3/13444 等...
编辑:
我找到了一种方法,但它看不到隐藏文件,如何让他们在 for 循环中看到它们?
#!/bin/bash
copysync() {
countfiles() {
for …
Run Code Online (Sandbox Code Playgroud)