shell-break

[root@localhost ~]# cat break.sh 
#!/bin/bash

for i in 1 2 3
do
	for j in 4 5 6
	do
		if [ $i -eq 2 -a $j -eq 5 ]
		then
			break 2
		else
			echo "$i $j"	
		fi
	done
done

[root@localhost ~]# sh break.sh 
1 4
1 5
1 6
2 4
[root@localhost ~]# cat break.sh 
#!/bin/bash

for i in 1 2 3
do
	for j in 4 5 6
	do
		if [ $i -eq 2 -a $j -eq 5 ]
		then
			break 1
		else
			echo "$i $j"	
		fi
	done
done

[root@localhost ~]# sh break.sh 
1 4
1 5
1 6
2 4
3 4
3 5
3 6
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的HDFS Shell程序HShell的实现,可以满足题目要求: ```java import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.permission.FsAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.permission.PermissionStatus; import org.apache.hadoop.hdfs.DistributedFileSystem; public class HShell { private static final String USAGE = "Usage: HShell [-cp|-rm|-mv|-list|-find] [args...]"; public static void main(String[] args) { if (args.length < 1) { System.out.println(USAGE); return; } Configuration conf = new Configuration(); try { FileSystem fs = DistributedFileSystem.get(conf); switch (args[0]) { case "-cp": if (args.length < 3) { System.out.println("Usage: HShell -cp local_path hdfs_path"); return; } Path localPath = new Path(args[1]); Path hdfsPath = new Path(args[2]); fs.copyFromLocalFile(localPath, hdfsPath); break; case "-rm": if (args.length < 2) { System.out.println("Usage: HShell -rm [-r] path"); return; } Path path = new Path(args[1]); boolean recursive = false; if (args.length > 2 && args[1].equals("-r")) { recursive = true; path = new Path(args[2]); } if (recursive) { fs.delete(path, true); } else { fs.delete(path, false); } break; case "-mv": if (args.length < 3) { System.out.println("Usage: HShell -mv src_path dest_path"); return; } Path srcPath = new Path(args[1]); Path destPath = new Path(args[2]); fs.rename(srcPath, destPath); break; case "-list": if (args.length < 2) { System.out.println("Usage: HShell -list path"); return; } Path listPath = new Path(args[1]); List<FileStatus> statuses = listStatus(fs, listPath); for (FileStatus status : statuses) { System.out.println(status.toString()); } break; case "-find": if (args.length < 3) { System.out.println("Usage: HShell -find filename path"); return; } String filename = args[1]; Path findPath = new Path(args[2]); List<FileStatus> foundStatuses = find(fs, findPath, filename); for (FileStatus status : foundStatuses) { System.out.println(status.getPath().toString()); } break; default: System.out.println(USAGE); break; } } catch (IOException e) { e.printStackTrace(); } } private static List<FileStatus> listStatus(FileSystem fs, Path path) throws IOException { List<FileStatus> statuses = new ArrayList<>(); FileStatus[] fileStatuses = fs.listStatus(path); statuses.addAll(Arrays.asList(fileStatuses)); return statuses; } private static List<FileStatus> find(FileSystem fs, Path path, String filename) throws IOException { List<FileStatus> foundStatuses = new ArrayList<>(); List<FileStatus> statuses = listStatus(fs, path); for (FileStatus status : statuses) { if (status.isFile() && status.getPath().getName().equals(filename)) { foundStatuses.add(status); } else if (status.isDirectory()) { foundStatuses.addAll(find(fs, status.getPath(), filename)); } } return foundStatuses; } } ``` 上面的代码实现了以下功能: 1. 使用HShell -cp local_path hdfs_path,将文件从Linux本地文件系统拷贝到HDFS指定路径上。 2. 使用HShell -rm [-r] path,删除文件或目录(使用-r参数表示递归删除)。 3. 使用HShell -mv src_path dest_path,移动文件或重命名文件。 4. 使用HShell -list path,显示某个文件的信息或者某个目录的信息。 5. 使用HShell -find filename path,递归查找某个文件名的文件。 请注意,上面的代码仅作为示例,可能存在未处理的异常和其他问题,需要根据实际情况进行修改和完善。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值