Skip to main content
edited title
Link
Inian
  • 87k
  • 15
  • 166
  • 183

Check FIlename whichfilename contains Stringa string in Bashbash script

edit the changes to see clearly
Source Link
gudok
  • 4.2k
  • 2
  • 23
  • 31

I had written a script for moving/Copying files to particular folder. I need to check the filenames and move to respective folders. I can read the filenamess but, checking the filename contains a string giving the error.

Here my script ::

for eachfile in *;do*; do
  echo "INSIDE"
  echo $eachfile
  if [ [ $eachfile =  "CHPOE05"* ] ];
  then
    echo  $eachfile
  else
    echo "invalid"
  fi
done

Below is my error::

Uploading file IN PCS FOLDER
INSIDE
CHPOE0500001.txt
INCOK1IGT1.sh: line 44: [: too many arguments
invalid
INSIDE
CHPOE050i1001.txt
INCOK1IGT1.sh: line 44: [: too many arguments

I had written a script for moving/Copying files to particular folder. I need to check the filenames and move to respective folders. I can read the filenamess but, checking the filename contains a string giving the error.

Here my script ::

for eachfile in *;do
echo "INSIDE"
echo $eachfile
if [ [ $eachfile =  "CHPOE05"* ] ];
 then
echo  $eachfile
else
echo "invalid"
fi
done

Below is my error::

Uploading file IN PCS FOLDER
INSIDE
CHPOE0500001.txt
INCOK1IGT1.sh: line 44: [: too many arguments
invalid
INSIDE
CHPOE050i1001.txt
INCOK1IGT1.sh: line 44: [: too many arguments

I had written a script for moving/Copying files to particular folder. I need to check the filenames and move to respective folders. I can read the filenamess but, checking the filename contains a string giving the error.

Here my script ::

for eachfile in *; do
  echo "INSIDE"
  echo $eachfile
  if [ [ $eachfile =  "CHPOE05"* ] ]; then
    echo  $eachfile
  else
    echo "invalid"
  fi
done

Below is my error:

Uploading file IN PCS FOLDER
INSIDE
CHPOE0500001.txt
INCOK1IGT1.sh: line 44: [: too many arguments
invalid
INSIDE
CHPOE050i1001.txt
INCOK1IGT1.sh: line 44: [: too many arguments

I had written a script for moving/Copying files to particular folder. I need to check the filenames and move to respective folders. I can read the filenamess but, checking the filename contains a string giving the error.

Here my script :: for eachfile in ;do echo "INSIDE" echo $eachfile if [ [ $eachfile = "CHPOE05" ] ]; then echo $eachfile else echo "invalid" fi done

for eachfile in *;do
echo "INSIDE"
echo $eachfile
if [ [ $eachfile =  "CHPOE05"* ] ];
then
echo  $eachfile
else
echo "invalid"
fi
done

Below is my error:: Uploading file IN PCS FOLDER INSIDE CHPOE0500001.txt INCOK1IGT1.sh: line 44: [: too many arguments invalid INSIDE CHPOE050i1001.txt INCOK1IGT1.sh: line 44: [: too many arguments

Uploading file IN PCS FOLDER
INSIDE
CHPOE0500001.txt
INCOK1IGT1.sh: line 44: [: too many arguments
invalid
INSIDE
CHPOE050i1001.txt
INCOK1IGT1.sh: line 44: [: too many arguments

I had written a script for moving/Copying files to particular folder. I need to check the filenames and move to respective folders. I can read the filenamess but, checking the filename contains a string giving the error.

Here my script :: for eachfile in ;do echo "INSIDE" echo $eachfile if [ [ $eachfile = "CHPOE05" ] ]; then echo $eachfile else echo "invalid" fi done

Below is my error:: Uploading file IN PCS FOLDER INSIDE CHPOE0500001.txt INCOK1IGT1.sh: line 44: [: too many arguments invalid INSIDE CHPOE050i1001.txt INCOK1IGT1.sh: line 44: [: too many arguments

I had written a script for moving/Copying files to particular folder. I need to check the filenames and move to respective folders. I can read the filenamess but, checking the filename contains a string giving the error.

Here my script ::

for eachfile in *;do
echo "INSIDE"
echo $eachfile
if [ [ $eachfile =  "CHPOE05"* ] ];
then
echo  $eachfile
else
echo "invalid"
fi
done

Below is my error::

Uploading file IN PCS FOLDER
INSIDE
CHPOE0500001.txt
INCOK1IGT1.sh: line 44: [: too many arguments
invalid
INSIDE
CHPOE050i1001.txt
INCOK1IGT1.sh: line 44: [: too many arguments
Source Link
Loading