I am working on PHP file and want to delete the first line from a text file.
Here is my code:
shell_exec("C:\\cygwin64\\bin\\bash.exe --login -c \"sed '1d' $text_files_path/diffFile.txt\"");
shell_exec("C:\\cygwin64\\bin\\bash.exe --login -c 'sed '1d' $text_files_path/diffFile.txt'");
shell_exec("C:\\cygwin64\\bin\\bash.exe --login -c 'tail -n +2 $text_files_path/diffFile.txt'");
shell_exec("C:\\cygwin64\\bin\\bash.exe --login -c \"tail -n +2 '$text_files_path/diffFile.txt'\"");
But, nothing works!
Any idea please?
Your variable should be double-quoted to allow shell parameter expansion.
Try this :
shell_exec('C:\\cygwin64\\bin\\bash.exe --login -c "sed -i \"1d\" "$text_files_path"/diffFile.txt"');
Note : I added the -i
option that edit the file in place.