为管道中的变量分配grep值

时间:2017-12-01 09:21:13

标签: bash grep

我的管道状况如下:

<TableLayout
                android:id="@+id/orderDetails"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:stretchColumns="1"
                android:background="@drawable/cell_shape"
                android:layout_below="@id/terms"
                android:layout_marginBottom="10dp">
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <TextView
                        android:layout_column="1"
                        android:text="Details"
                        android:layout_marginStart="15dp"
                        android:textStyle="bold"/>
                </TableRow>
                <View
                    android:layout_height="1dp"
                    android:background="@color/lightGray"/>
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <TextView
                        android:id="@+id/orderName"
                        android:layout_column="1"
                        android:padding="3dip"
                        android:layout_marginStart="15dp"/>
                    <TextView
                        android:id="@+id/quantity"
                        android:layout_column="2"
                        android:gravity="end"
                        android:padding="3dip"/>
                    <TextView
                        android:id="@+id/price"
                        android:layout_column="3"
                        android:gravity="end"
                        android:padding="3dip"
                        android:layout_marginEnd="15dp"/>
                </TableRow>
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <TextView
                        android:layout_column="1"
                        android:padding="3dip"
                        android:text="Total Amount"
                        android:layout_marginStart="15dp"/>
                    <TextView
                        android:layout_column="3"
                        android:id="@+id/totalamount"
                        android:gravity="right"
                        android:padding="3dip"
                        android:layout_marginEnd="15dp"/>
                </TableRow>

            </TableLayout>
            <TableLayout
                android:id="@+id/orderAddress"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:stretchColumns="1"
                android:background="@drawable/cell_shape"
                android:layout_below="@id/orderDetails"
                android:layout_marginBottom="10dp">
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <TextView
                        android:layout_column="1"
                        android:text="Pickup Address"
                        android:layout_marginStart="15dp"
                        android:textStyle="bold"/>
                </TableRow>
                <View
                    android:layout_height="1dp"
                    android:background="@color/lightGray"/>
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <TextView
                        android:id="@+id/address"
                        android:layout_column="1"
                        android:padding="3dip"
                        android:layout_marginStart="15dp"/>
                </TableRow>
            </TableLayout>
            <TableLayout
                android:id="@+id/noteForCheifa"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:stretchColumns="1"
                android:background="@drawable/cell_shape"
                android:layout_below="@id/orderAddress"
                android:layout_marginBottom="10dp">
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <TextView
                        android:layout_column="1"
                        android:text="Note For Chef"
                        android:layout_marginStart="15dp"
                        android:textStyle="bold"/>
                </TableRow>
                <View
                    android:layout_height="1dp"
                    android:background="@color/lightGray"/>
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <TextView
                        android:id="@+id/ChefNote"
                        android:layout_column="1"
                        android:padding="3dip"
                        android:layout_marginStart="15dp"/>
                </TableRow>
            </TableLayout>



            <TableLayout
                android:id="@+id/paymentmode"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:stretchColumns="1"
                android:background="@drawable/cell_shape"
                android:layout_below="@id/noteForCheifa"
                android:layout_marginBottom="90dp">
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <TextView
                        android:layout_column="1"
                        android:text="Select Payment Method"
                        android:layout_marginStart="15dp"
                        android:textStyle="bold"/>
                </TableRow>
                <View
                    android:layout_height="1dp"
                    android:background="@color/lightGray"/>
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <RadioGroup
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/RGroup">
                        <RadioButton
                            android:id="@+id/SelectTezUpi"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="@string/Tez"
                            android:buttonTint="@color/colorPrimary"/>
                        <RadioButton
                            android:id="@+id/paytm"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="Paytm"
                            android:buttonTint="@color/colorPrimary"/>
                    </RadioGroup>

                </TableRow>
            </TableLayout>

现在我想从shell变量中获取if true | openssl s_client -connect $SSL_URL | openssl x509 -noout -dates -checkend 0 | grep 'notAfter'; 返回的值,我该怎么做呢。

我试过这个

grep 'notAfter'

但它不起作用。

1 个答案:

答案 0 :(得分:1)

您可能正在寻找

if A=$(openssl s_client -connect "$SSL_URL" </dev/null | 
    openssl x509 -noout -dates -checkend 0 |
    grep 'notAfter')
then
    :

这将管道的输出分配给变量A,并检查grep的结果代码;如果成功(即找到匹配),则采用条件的then分支。

来自true的管道奇怪且非传统;我想这样做的目的是确保它在标准输入上没有收到任何有用的东西。通常的方法是将标准输入重定向到来自/dev/null,这样我就可以这样做了。

最后,还要注意变量的正确引用。如果SSL_URL碰巧包含shell元字符,则会出现错误或最坏情况下出现安全问题。

相关问题