我想知道如何获取传递给bash函数的最后一个参数,如:
#!/bin/bash
function hello() {
all=$@ # all arguments
n=$# # number of arguments
first_arg=$1 # argument one
last_arg= ??? # How to get the last argument?
}
如何将$last_arg
设置为传递给函数的最后一个参数的值?
答案 0 :(得分:2)
如果from tkinter import *
class Window():
def __init__(self, root):
self.f = Frame(root)
self.f.pack()
self.e = Entry(self.f, width = 20)
self.e.pack(side = LEFT)
self.b = Button(self.f, width = 15, text = "OK", command = lambda: self.OK(root))
self.b.pack(side = RIGHT)
def OK(self, root):
print ("Accessing entry inside class: %s" %self.e.get()) #Could pass to pri.py here
self.word = self.e.get()
new = self.newWindow()
root.wait_window(new)
root.destroy()
def newWindow(self):
def done(newWindow):
newWindow.destroy()
newWindow = Toplevel()
newWindow.tkraise() # <- Personally never needed this, but it's in
l = Label(newWindow, text = "Here is the variable in a top window: %s" %self.word) #Using the variable in another window
l.pack(side = LEFT)
b = Button(newWindow, text = "Done", command = lambda: done(newWindow))
b.pack(side = RIGHT)
return newWindow
root = Tk()
w = Window(root)
w.f.mainloop()
print ("Accessing entry outside class: %s" %w.word) #Or here
拥有all
,则最后一个参数为$@