精通Unix、Linux和OS X的Shell编程

5星 · 超过95%的资源 需积分: 9 216 下载量 57 浏览量 更新于2024-07-20 2 收藏 5.26MB PDF 举报
"Shell Programming in Unix, Linux and OS X 4th Ed" 是一本全面更新的教程,专注于POSIX标准shell编程,旨在教你如何在这一有用的编程环境中开发程序,充分利用Unix和类Unix操作系统的核心功能。这本书由Kochan和Wood撰写,通过一系列实践示例,教你如何编写强大的shell脚本,利用shell的内置决策和循环结构,以及shell的强大引用机制。此外,还涵盖了Korn和Bash shell的主要特性,帮助读者识别不同版本shell语言之间的主要差异,并定制自己的Unix系统环境。 书中内容包括: 1. 对Unix基础工具的快速回顾,为后续学习打下基础。 2. 解释什么是shell,其在Unix系统中的作用和重要性。 3. 强调shell编程所需的“工具”,即常用Unix命令和实用程序。 4. 逐步引导读者编写和调试shell脚本,理解它们在shell环境中的工作方式。 5. 详细讲解shell的引用机制,如引号的使用和特殊字符的处理。 6. 如何处理脚本参数,传递和接收数据。 7. 使用决策结构(如if、case语句)进行条件判断。 8. 学习循环结构,如for、while循环。 9. 讲解读取和打印数据的方法,处理输入输出。 10. 深入了解环境变量,定制shell环境。 11. 进一步探讨参数的使用,包括位置参数、关键字参数等。 12. 整理和处理遗留问题,解决编程中可能遇到的常见挑战。 13. 回顾之前章节的内容,用一个实际案例Rolo来整合所学知识。 14. 探讨交互式和非标准shell特性,如历史记录、命令编辑等。 附录A提供了shell的总结,附录B提供了更多学习资源的指引。 通过本书,读者将能够充分利用Unix系统提供的众多工具,编写出适应各种应用场景的shell脚本,掌握shell编程的核心技巧,并对Korn和Bash shell有深入的理解。无论你是初学者还是经验丰富的开发者,这本书都将是你提升shell编程技能的理想指南。

改进以下代码 currentpath = os.path.dirname(os.path.realpath(__file__)) time_date = '{}{}'.format(self.time_date,self.random_char(5)) contents = os.path.join(currentpath, time_date, self.ref.split('/')[-1]) ref = self.ref.split('/')[-1] private_token = self.gl.private_token path = "lib" if ref == "master": if os.path.exists(os.path.join(contents, self.name)): subprocess.call("rm -rf {} ".format(os.path.join(contents, self.name)), shell=True, cwd=contents) time.sleep(3) retcode = start.clone(int(self.project_id), ref, contents, private_token) if retcode == 0: start.clone_frontend(self.get_frontend()[0],self.get_frontend()[1], contents, private_token,self.get_frontend()[2] ) start.clone_abc(self.get_abc()[0], self.get_abc()[1], contents, private_token,"mc_abc") start.clone_model(start.get_clkrst()[0], start.get_clkrst()[1], contents, private_token,"clkrst") start.clone_model(start.get_ara()[0], start.get_ara()[1], contents, private_token,"ara") start.clone_model(start.get_wfl()[0], start.get_wfl()[1], contents, private_token,"wfl") subprocess.call("echo '*.t' >> {}".format(os.path.join(contents, self.name, ".gitignore")),shell=True) code = start.make_lib(os.path.join(contents, self.name)) rel, err = code.communicate() if "make: *** [main] Error 2" in err.decode('utf-8'): print("loading push error log") filename = os.path.join(contents, self.name, "error_make_log") subprocess.call("echo '' > {}".format(filename), shell=True, cwd=contents) start.error_make(filename, rel.decode('utf-8') ) start.error_make(filename, err.decode('utf-8') ) else: print("loading push libs") # start.push_lib(os.path.join(contents, self.name), path, ref)

2023-06-01 上传

function spawnEnemy(n) { setInterval(() => { for (let idx = 0; idx < n; idx++) { let radius = Math.random() * (20 - 4) + 8; let x = Math.random() * canvas.width - radius; let y = Math.random() * canvas.height + radius; let color = hsl(${Math.floor(Math.random() * 360)},70%,50%); let angle = Math.atan2(player.y - y, player.x - x); let vector = { x: Math.cos(angle) * 2, y: Math.sin(angle) * 2, }; let enemyObj = new Enemy(x, y, radius, color, vector); enemyArrays.push(enemyObj); } }, 1000); } function animate() { if (!gameStarted) { // 如果游戏未开始,不执行游戏逻辑 return; } player.draw(ctx); ctx.fillStyle = "rgba(0,0,0,0.2)"; // ctx.clearRect(0,0,canvas.width,canvas.height); ctx.fillRect(0, 0, canvas.width, canvas.height); enemyArrays.forEach((enemy, idx) => { enemy.draw(ctx); enemy.update(); // 判断,从enemyArrays数组中删除 if (enemy.x <= 0 || enemy.x >= canvas.width || enemy.y <= 0 || enemy.y >= canvas.height) { enemyArrays.splice(idx, 1); } }); //shell shellArrays.forEach((shell, idx) => { shell.draw(ctx); shell.update(); enemyArrays.forEach((enemy, j) => { // 碰撞判断 let distance = Math.hypot(shell.x - enemy.x, shell.y - enemy.y); if (distance < 20) { enemyArrays.splice(j, 1); shellArrays.splice(idx, 1); createParticle(particleNum, enemy.x, enemy.y, enemy.color); score += 10; scoreText.innerHTML = 'Score: ' + score; } }); // 范围判断 if (shell.x <= 0 || shell.x >= canvas.width || shell.y <= 0 || shell.y >= canvas.height) { shellArrays.splice(idx, 1); } }); // 粒子 particleArrays.forEach((particle, idx) => { particle.draw(ctx); particle.update(); if (particle.alpha <= 0.1) { particleArrays.splice(idx, 1); } }); window.requestAnimationFrame(animate); } // 创建粒子 function createParticle(n, x, y, color) { for (let i = 0; i < n; i++) { let vector = { x: Math.random() * 3 - 1.5, y: Math.random() * 3 - 1.5, }; particleArrays.push(new Particle(x, y, 3, color, 1, vector)); } } function handleClick() { window.addEventListener("click", (e) => { let x = e.clientX; let y = e.clientY; let color = "white"; let radius = 10; let radian = Math.atan2(y - player.y, x - player.x); let vector = { x: Math.cos(radian) * 6, y: Math.sin(radian) * 6, }; let shell = new Shell(player.x, player.y, radius, color, vector); shellArrays.push(shell); }) } 子弹和敌人的运动方向是怎么产生的

2023-06-02 上传