如何存储" ls $ PATH * .log"并将结果存储在一个变量中,如LAST =" ls $ PATH * .log" ??
感谢
#!bin/sh
var="$(ls -l $1*.log)" work correctly
echo "${var}" <-i can view list file
file= /my/path/$1*.log
var="$(ls -l $file*.log)" <- dont work
为什么?
答案 0 :(得分:1)
您的代码:
file= /my/path/$1*.log #you have already defined pattern here
var="$(ls -l $file*.log)" #this line will try to list /my/path/$1*.log*.log
应该解决这个问题:
file=/my/path/$1*.log #also removed spaces after/before = sign
var="$(ls -l $file)" #this line will tri to list /my/path/$1*.log
OR
file=/my/path/$1 #also removed spaces after/before = sign
var="$(ls -l $file*.log)" #this line will try to list /my/path/$1*.log