简体   繁体   中英

How can I use an applescript list (copied to the clipboard) in a bash array?

In applescript I use the following code to set the clipboard to a list (array): set the clipboard to {"4", "4", "5"}

Is it possible to assign the items of the list in the clipboard to a bash array? In applescript, the code for assigning the list items (from the clipboard) to a variable looks like this: set theList to list of (the clipboard) . What would be the bash equivalent for this code?

Thank you!

My answer to my question is as it follows. There's no Bash equivalent to set theList to list of (the clipboard) . But, there's this code that puts the content of the clipboard into a variable called "clipboard" (provided that the clipboard contains items separated by space or on separate lines).

#!/bin/bash

clipboard="$(pbpaste)" # get the content of the clipboard
theList=( $clipboard ) # make an array from the clipboard content

echo ${theList[1]} # proof that "theList" is an array

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM