我有以下 bash 脚本
counter=0
for file in /home/ec2-user/Workspace/events_parts/*
do
counter=$[counter + 1]
event=$(cat $file | jq '.Event')
echo $event
if [ "$event" = "Page Exceeded" ] || [ "$event" = "Reporting Time" ]; then
echo "Coming Here"
jq ".url = \"$(jq '.Message' $file | sed 's/.*proxy=\([^&]*\).*/\1/')\"" $file > events_parts/out_$file
else
jq ".url = null" $file > events_parts/out_$file
fi
done
它处理一组 JSON 文件。我想将它重定向到具有 out_$input_file_name 的文件名。但是变量文件打印出整个路径而不仅仅是文件名(例如/home/ec2-user/Workspace/events_parts/input.json
)我如何从中获取“输入文件名”?