Re: lftp and patterns

"Alexander V. Lukyanov" <[email protected]>
Newsgroups gmane.network.lftp.user
Message-ID <[email protected]>
On Tue, Jun 10, 2014 at 08:41:04AM +0000, [email protected] wrote:
> Hi Alexander,
> yep, we’ve already tried cls before. But regarding the exit code, it works the same as ls.

You can use temporary files like this:

	lftp> cls *.csv > listing
	lftp> source -e "test -s listing && echo LFTP-COMMAND"

It's not pretty, but works...

You can also try attached patch, which adds this possibility:

	glob .empty *.csv && echo "There are no *.csv files"

Suggestions on the command name are welcome (it's not released yet).

-- 
   Alexander.

_______________________________________________
lftp mailing list
[email protected]
http://univ.uniyar.ac.ru/mailman/listinfo/lftp
diff (text/plain, 1 KB)
diff --git a/src/commands.cc b/src/commands.cc
index e77d211..695c6cf 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -92,6 +92,8 @@ CMD(at);    CMD(find);   CMD(command); CMD(module);
 CMD(lpwd);  CMD(glob);	 CMD(chmod);   CMD(queue);
 CMD(repeat);CMD(get1);   CMD(tasks);   CMD(torrent);
 
+CMD(empty); CMD(true); CMD(false);
+
 #ifdef MODULE_CMD_MIRROR
 # define cmd_mirror 0
 #endif
@@ -489,6 +491,9 @@ const struct CmdExec::cmd_rec CmdExec::static_cmd_table[]=
 	 N_("Same as more, but filter each file through bzcat\n")},
 
    {".tasks",  cmd_tasks,  0,0},
+   {".empty",  cmd_empty,  0,0},
+   {".true",   cmd_true,   0,0},
+   {".false",  cmd_false,  0,0},
 };
 const int CmdExec::static_cmd_table_length=sizeof(static_cmd_table)/sizeof(static_cmd_table[0]);
 
@@ -3348,6 +3353,22 @@ CMD(tasks)
    return 0;
 }
 
+CMD(empty)
+{
+   exit_code=(args->count()>1 ? 1 : 0);
+   return 0;
+}
+CMD(true)
+{
+   exit_code=0;
+   return 0;
+}
+CMD(false)
+{
+   exit_code=1;
+   return 0;
+}
+
 CMD(eval)
 {
    int opt;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.