Questions on bash

Cixy 2004-10-14 11:23:53
Met some problems on bash programing:
1. how to read a line from file and save it into a variable?
2. how to reserve a string?
3. does reg exp support number caculation? how?
4. how to return value in a function and how to retrieve it outside function?
5. how to format the output string?

Thanks for your reply!
...全文
216 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Cixy 2004-10-18
  • 打赏
  • 举报
回复
唉,还是去UNIX站点寻求帮助吧,谢谢两位了
gettext 2004-10-15
  • 打赏
  • 举报
回复
用awk更合适。man awk
Cixy 2004-10-15
  • 打赏
  • 举报
回复
man awk... too many to read... I have to say my english is not good(use english just because no chinese ime installed on the lab pc)

so... could you please give a clear answer for my questions?

Thanks,
pacman2000 2004-10-14
  • 打赏
  • 举报
回复
1. read a < t.txt
2. ???
3. i=`expr $1 + 1` ?
4. man bash , see FUNCTIONS
5. printf
Cixy 2004-10-14
  • 打赏
  • 举报
回复
Thanks pacman and mahongxi,

pacman,
I tried your code, but only the first line was successfully read.
In fact in question 1, I want to write an iterator to go through the whole file line by line.
In question 2, I want to reverse a string (sorry for my typo :P)

mahongxi
In your method, how to count the number of lines in a file?

Thanks again and appreciate for you reply.
mahongxi 2004-10-14
  • 打赏
  • 举报
回复
1.
$line_str=$(sed "2 p" -n t.txt) 2 is line number
Your UNIX/Linux: The Ultimate Guide, written with both users and programmers in mind, is the ultimate UNIX/Linux text. Both pedagogical tool and exhaustive reference, it is well-suited to any course that includes UNIX or Linux. A strong pedagogical framework sets it apart from similar texts and allows beginning students to gain a firm grasp of fundamental concepts, while chapters on advanced topics inspire the more experienced reader to move beyond the basics. Nearly a thousand exercises and self-test questions provide a way for students to test and reinforce their understanding of the material. Table of Contents PART I UNIX for the User Chapter 1 Introducing UNIX Chapter 2 Becoming Familiar with UNIX Commands Chapter 3 The File System Chapter 4 File Attributes Chapter 5 The vi/vim Editor Chapter 6 The Shell Chapter 7 The Process Chapter 8 The Shell—Customizing the Environment Chapter 9 Simple Filters Chapter 10 Filters Using Regular Expressions—grep and sed Chapter 11 Networking Tools PART II UNIX for the Programmer Chapter 12 Filtering and Programming with awk Chapter 13 Shell Programming Chapter 14 perl—The Master Manipulator Chapter 15 Introducing C Chapter 16 Program Development Tools Chapter 17 Systems Programming I—Files Chapter 18 Systems Programming II—Process Control PART III System Administration Chapter 19 System Administration Appendix A The C Shell—Programming Constructs Appendix B The Korn and Bash Shells—Exclusive Programming Constructs Appendix C The GNU emacs Editor Appendix D vi/vim Command Reference Appendix E The Regular Expression Superset Appendix F The HOWTO Appendix G The ASCII Character Set Appendix H Glossary Appendix I Solutions to Self-Test Questions

23,224

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧