Shell array using

Source: Internet
Author: User

A brother in the forum to toss two variables at the same time, do not know how to toss. Later learned that you can use an array

All forget the shell and the array.


wrote a test program. Record it. I also have an impression in the future.

#!/bin/bashdeclare -a tmpfor i in $ (find /bin -type f) do     let c++    tmp[c]= "$i" donelen= "${#tmp [@]}"    #array  lengthc =200for i in $ (find /usr/bin -type f) do    let c++     tmp[c]= "$i" donei=0while [  $i  -le  $len  ]do     let i+=1    echo  "bin:${tmp[i]}; usr:${tmp[i+200]}" Done$ bash  a.sh  bin:/bin/cp usr:/usr/bin/semodule_linkbin:/bin/redhat_lsb_init usr:/usr/bin/ gst-launchbin:/bin/readlink usr:/usr/bin/opgprofbin:/bin/unicode_start usr:/usr/bin/eu-stringsbin:/ bin/ps usr:/usr/bin/pango-querymodules-64bin:/bin/lsblk usr:/usr/bin/wbin:/bin/sleep usr:/usr/ bin/smbta-utilbin:/bin/setserial usr:/usr/bin/aserverbin:/bin/unicode_stop usr:/usr/bin/patchbin:/ bin/cgget usr:/usr/bin/Pdftopsbin:/bin/nano usr:/usr/bin/lzmainfobin:/bin/cgdelete usr:/usr/bin/gstackbin:/bin/ln usr :/usr/bin/rngtestbin:/bin/mkdir usr:/usr/bin/nfs4_setfaclbin:/bin/mknod usr:/usr/bin/vimtutorbin:/ Bin/dumpkeys usr:/usr/bin/op-check-perfeventsbin:/bin/ipcalc usr:/usr/bin/sedispolbin:/bin/gzip  usr:/usr/bin/reporter-mailxbin:/bin/true usr:/usr/bin/tiff2pdfbin:/bin/mv usr:/usr/bin/ urlgrabberbin:/bin/dbus-uuidgen usr:/usr/bin/grofferbin:/bin/cgsnapshot usr:/usr/bin/smbcquotasbin:/ bin/env usr:/usr/bin/nfs4_getfaclbin:/bin/arch usr:/usr/bin/repomanagebin:/bin/echo usr:/usr/ Bin/eu-unstripbin:/bin/touch usr:/usr/bin/.ssh.hmac

The first time the script takes the result length is the maximum length of the back while.


Arrays can also be directly

For i in ${array[@]}; Do ...; Done

But to take two variables at the same time is not good toss.


In addition to the array there are shards, replacements and other advanced features, this is not currently available. Don't write it.


Or toss Python-based ...

Shell array using

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.