-1

I have a line in my script as below:

ls -l $In_File_Path$In_File_NAME.*.txt >> vendor_file_list.dat

When I run this from the linux command prompt it works and populates the vendor_file_list.dat with file name; but in a script it fails stating no file or directory found.

Can anybody please help?

Raad
  • 4,540
  • 2
  • 24
  • 41
shruti rawat
  • 241
  • 1
  • 7
  • 19
  • 1
    Check if your working directory in the script is the same. (Run `pwd` from the prompt and from the script.) – Kirill Bulygin Oct 12 '18 at 08:46
  • @KirillBulygin I am giving full path of file while doing ls -l – shruti rawat Oct 12 '18 at 08:49
  • Can you add an echo statement and check what is the value for "$In_File_Path$In_File_NAME.*.txt" in your script. – Nishu Tayal Oct 12 '18 at 08:49
  • @NishuTayal /usr/local/distrack/gartrack/ftp/GTS.*.txt: No such file or directory GTSVendorLoad.sh[44]: syntax error at line 64 : `else' unexpected dcsdb01 /usr/local/distrack/gartrack/external >ls -l /usr/local/distrack/gartrack/ftp/GTS.*.txt -rw-r--r-- 1 distrack payroll 157 Oct 3 01:34 /usr/local/distrack/gartrack/ftp/GTS.20181003063954.txt -rw-r--r-- 1 distrack payroll 336 Oct 3 03:31 /usr/local/distrack/gartrack/ftp/GTS.20181003084007.txt – shruti rawat Oct 12 '18 at 08:51
  • there's a syntax error in your script, so that needs to be corrected first - can you post up the whole script, or at least the major control structures in/around the ls command? – Raad Oct 12 '18 at 09:05
  • `/usr/local/distrack/gartrack/ftp/GTS.*.txt: No such file or directory` means that there are no files matching that pattern. The `*` is retained if `bash` does not find files matching the pattern. – cdarke Oct 12 '18 at 09:05
  • Possible duplicate of [How do I escape the wildcard/asterisk character in bash?](https://stackoverflow.com/questions/102049/how-do-i-escape-the-wildcard-asterisk-character-in-bash) – phuzi Oct 12 '18 at 09:14
  • @phuzi I don't think that's the actual problem here; seems like the OP actually wants the wildcard to be expanded (even though the title says completely something else). – tripleee Oct 12 '18 at 09:18
  • How are `In_File_Path` and `In_File_NAME` being set? – chepner Oct 12 '18 at 13:56

1 Answers1

0

2 things:

  1. As Kirill says in the comments, make sure you are executing the script in the directory you want to

  2. There are 2 shell variables in your ls command $In_File_Path and $In_File_NAME, so you need to make sure these are defined correctly in your script (they will be case-sensitive)

Raad
  • 4,540
  • 2
  • 24
  • 41
  • /usr/local/distrack/gartrack/ftp/GTS.*.txt: No such file or directory GTSVendorLoad.sh[44]: syntax error at line 64 : `else' unexpected dcsdb01 /usr/local/distrack/gartrack/external >ls -l /usr/local/distrack/gartrack/ftp/GTS.*.txt -rw-r--r-- 1 distrack payroll 157 Oct 3 01:34 /usr/local/distrack/gartrack/ftp/GTS.20181003063954.txt – shruti rawat Oct 12 '18 at 08:52
  • Such error messages would help us much more if we could see the code they refer to (`syntax error at line 64`, etc.). – Alfe Oct 12 '18 at 09:02