14 lines
492 B
Bash
14 lines
492 B
Bash
|
#!/bin/bash
|
|||
|
|
|||
|
# 编写一个Shell脚本,接受一个文件路径作为参数,并检查该文件是否存在。如果存在,则输出 "文件名和文件大小",否则输出 "File does not exist."
|
|||
|
|
|||
|
# 方法一
|
|||
|
if [ -e $1 ]; then
|
|||
|
output=`ls -lh $1 | awk '{print $5}'`
|
|||
|
echo "文件名: $1, 文件大小: $output"
|
|||
|
else
|
|||
|
echo "File does not exist."
|
|||
|
fi
|
|||
|
|
|||
|
# 方法二
|
|||
|
[ -e $1 ] && echo "文件名: $1, 文件大小: `ls -lh $1 | awk '{print $5}'`" || echo "File does not exist."
|