too*_*oop 1 unix linux bash shell scripting
从存储的日期变量中提取星期几的语法是什么?该dateinfile格式始终[alphanum]_YYYYMMDD.
在这个伪代码示例中,试图在dayofweek星期六存储:
#! /bin/bash
dateinfile="P_20090530"
dayofweek="$dateinfile -u +%A"
Run Code Online (Sandbox Code Playgroud)
[me@home]$ date --date=${dateinfile#?_} "+%A"
Saturday
Run Code Online (Sandbox Code Playgroud)
或者,按照您的要求提出:
[me@home]$ dayofweek=$(date --date=${dateinfile#?_} "+%A")
[me@home]$ echo $dayofweek
Saturday
Run Code Online (Sandbox Code Playgroud)