从Linux脚本stdin读取导出命令

时间:2019-11-25 03:10:48

标签: bash shell

我编写了一个脚本,需要在此脚本中使用export命令输入凭据。 我正在使用read命令在脚本中获取这些值。

这是我在脚本要求输入时需要输入的内容。我想一次就给出全部输入。

library(DT)
library(shiny)

get_set_rows <- function(idx = NULL) {

  cb = c(
    "var id = $(table.table().node()).closest('.datatables').attr('id');",
    "table.on('click', 'tbody', function(){",
    "  setTimeout(function(){",
    "    var indexes = table.rows({selected:true}).indexes();",
    "    var indices = Array(indexes.length);",
    "    for(var i = 0; i < indices.length; ++i){",
    "      indices[i] = indexes[i] + 1;",
    "    }",
    "    Shiny.setInputValue(id + '_rows_selected', indices);",
    "  }, 0);",
    "});"
  )

  if(!is.null(idx)) {

    cb = c(cb, sprintf('table.rows([%s]).select();', paste(idx - 1, collapse = ','))) #Subtracting 1 since DT uses base indexing

  } else {

    cb = c(cb, 'table.rows().deselect();')

  }

  JS(cb)

}

setInputVal <- function(session, inputId, value) {
  session$sendCustomMessage(type = 'setInputVal', message = list(id = inputId, value = value))
}

shinyApp(
  ui = fluidPage(
    tags$head(tags$script("Shiny.addCustomMessageHandler('setInputVal', function(data) {
  Shiny.setInputValue(data.id, data.value);
});")),
    actionButton('edit', 'Edit'), 
    bsModal(
      id = 'modal', title = 'Title', trigger = 'edit',
      DTOutput('table'),
      actionButton('apply', 'Apply'), 
      actionButton('cancel', 'Cancel')
    )
  ),

  server = function(input, output, session) {  

    rv = reactiveValues(selected_rows =  NULL)

    output$table <- renderDT({

      datatable(
        iris,
        callback = get_set_rows(input$table_rows_selected),
        options = list(select = list(
          style = "multi", 
          selector = "td:not(.notselectable)")),
        extensions = "Select", selection = "none")

    }, server = FALSE)


    observeEvent(input$apply, {

      rv$selected_cols = input$table_rows_selected

      toggleModal(session, 'modal')

      print(paste('rv$selected_cols at Apply:', paste(rv$selected_cols, collapse = ', ')))

    })


    observeEvent(input$cancel, {

      setInputVal(session, 'table_rows_selected', rv$selected_cols)

      toggleModal(session, 'modal')
    })

    observe(print(paste('input$table_rows_selected:', paste(input$table_rows_selected, collapse = ', '))))

  }
)

脚本的一部分:

export AWS_ACCESS_KEY_ID="XXXXXXX"
export AWS_SECRET_ACCESS_KEY="XXXXX"
export AWS_SESSION_TOKEN="XXXXXXX"

此脚本采用导出的证书,然后使用证书运行aws cli。 此脚本在一个循环中运行,在该循环中,我需要每次提供一组输入凭据(AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_SESSION_TOKEN)

0 个答案:

没有答案