Command call containing variables in Ksh

Source: Internet
Author: User

When a command containing variable A is stored in a variable B, it is possible to make an error when using $ ($b). As the following code can sometimes be executed successfully, sometimes a "ipcs|grep xxx can not be found" error occurs.

Ifs= "" If Islinux then ipcscmd= "IPCS" Else ipcscmd= "Ipcs|grep $LOGNAME" fi for Eachline in $ ($IPCSCMD) do ifs= "" # Handle IPCs ... done

The root of the problem should be the analysis of Ipcscmd. If you change the code to the following form, you can do it correctly. Notice the change of IFS--after changing to the form below, you must change the IFS within the loop to space and tab.

Ifs= "" If Islinux then IPCs else Ipcs|grep $LOGNAME fi | While read eachline does ifs= "" # Space and Tab # Handle IPCs ... done

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.