将cURL输出分配给Bash中的变量(Assign output to variable in Bash)
我试图将cURL的输出分配给如下变量:
#!/bin/sh $IP=`curl automation.whatismyip.com/n09230945.asp` echo $IP sed s/IP/$IP/ nsupdate.txt | nsupdate
但是,当我运行脚本时,会发生以下情况:
./update.sh: 3: =[my ip address]: not found
如何正确地输出到
$IP
?I'm trying to assign the output of cURL into a variable like so:
#!/bin/sh $IP=`curl automation.whatismyip.com/n09230945.asp` echo $IP sed s/IP/$IP/ nsupdate.txt | nsupdate
However, when I run the script the following happens:
./update.sh: 3: =[my ip address]: not found
How can I get the output into
$IP
correctly?
原文:https://stackoverflow.com/questions/8737638
最满意答案
TCustomForm
有一个受保护的过程定义为:procedure TCustomForm.VisibleChanging; begin if (FormStyle = fsMDIChild) and Visible and (Parent = nil) then raise EInvalidOperation.Create(SMDIChildNotVisible); end;
在您的MDI子窗口中覆盖它:
procedure TMDIChildForm.VisibleChanging; begin // :-P end;
在阅读了Jeroen的评论后,我尝试了另一种解决方案,但也有一点点闪烁:
procedure TMDIChildForm.VisibleChanging; begin if Visible then FormStyle := fsNormal else FormStyle := fsMDIChild; end;
也许这适用于所有Windows版本。
PS:我没有发现Windows 2k3SP2 x86和Windows 7 Ultimate x86上的第一个解决方案有任何问题
There is a protected procedure in
TCustomForm
defined as:procedure TCustomForm.VisibleChanging; begin if (FormStyle = fsMDIChild) and Visible and (Parent = nil) then raise EInvalidOperation.Create(SMDIChildNotVisible); end;
Override it in your MDI child windows as:
procedure TMDIChildForm.VisibleChanging; begin // :-P end;
After reading Jeroen's comment, I tried another solution which works as well, but with a little flickering:
procedure TMDIChildForm.VisibleChanging; begin if Visible then FormStyle := fsNormal else FormStyle := fsMDIChild; end;
Maybe this works on all Windows versions.
PS: I didn't find any problem with the first solution on Windows 2k3SP2 x86 and Windows 7 Ultimate x86
相关问答
更多-
TCustomForm有一个受保护的过程定义为: procedure TCustomForm.VisibleChanging; begin if (FormStyle = fsMDIChild) and Visible and (Parent = nil) then raise EInvalidOperation.Create(SMDIChildNotVisible); end; 在您的MDI子窗口中覆盖它: procedure TMDIChildForm.VisibleChanging; b ...
-
在第一个MDI子元素中,您可以创建一个secon MDI子元素的实例,将第二个实例的MdiParent设置为等于第一个子元素的MdiParent并显示该子元素。 因此,在第一个Mdi子代中,以下代码将显示第二个MDI子代 Dim mdiChildForm As New MyMdiChild mdiChildForm.MdiParent = Me.MdiParent mdiChildForm.Show() In the first MDI child you can create an instance ...
-
您需要跟踪表单状态,以便您知道需要创建一个新表单。 喜欢这个: private Form2 f2; private void button1_Click(object sender, EventArgs e) { if (f2 == null) { f2 = new Form2(); f2.MdiParent = this; f2.FormClosed += delegate { f2 = null; }; f2.Show(); ...
-
我可以使用以下代码重现这一点: Public Class Form1 Private Sub Open(sender As System.Object, e As System.EventArgs) Handles Button1.Click Me.BeginInvoke(Sub() Me.CreateMDIChildForm()) End Sub Private Sub CreateMDIChildForm() Dim f As New Form ...
-
听起来你正在让你的LoginForm自动创建,并且它首先被创建。 这不起作用,因为Application.CreateForm在项目文件中创建的第一个表单变为Application.MainForm 。 通过成为MDI应用程序, MainForm必须是MDI父窗口。 解决方案通常是不自动创建您的登录表单,而是自己创建。 为此,您需要编辑.dpr文件( Project->View Source from IDE的主菜单)。 您的项目源现在应该看起来像这样(显然,在Application.CreateForm调 ...
-
如果MDI子窗体没有ControlBox,如何打开和关闭它们(How to open and close MDI child forms if they do not have a ControlBox)[2021-10-15]
在显示下一个孩子之前,通常不需要隐藏一个mdi孩子,但是时间可能会混淆,在这种情况下,错误的表格最终可能会排在最前面。 这可能在启动时或加载或关闭文件时发生。 可能在父完成加载之前加载子表单,而父表单尚未最大化。 子表单可以在父表单中正确最大化,但随后父表单变大。 您可以通过在父级的Shown事件中将子表单设置为最大化(或调整大小?)来解决此问题。 您也可以在父级的ResizeEnd事件中执行此操作。 正如汉斯所说,假设你有时间进行改变,现在使用Tabs代替MDI更为社会可接受。 You normally ... -
要创建不可见的MDI子窗体,请将其Visible属性设置为False ,此外,您必须禁用强制显示它们的VCL行为。 这发生在TCustomForm的FormStyle属性设置器上,它为MDI子窗体设置Visible为True 。 如果在对象检查器中设置FormStyle ,则在创建表单期间将调用属性设置器,并且不会立即显示该表单,而是仅在构造完成后显示。 这允许您通过重写AfterConstruction()方法来重置显示表单的请求,如下所示: procedure TMDIChild.AfterConstr ...
-
当我尝试时,对我来说工作正常: type TMDIChildForm = class(TForm) private { Private declarations } procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND; public { Public declarations } end; procedure TMDIChildForm.WMSysCommand(var Msg: ...
-
原生Windows MDI实现无法处理无边界MDI子窗口。 不幸的是,Winforms忘记执行这一限制。 您可以在Show()调用后移动WindowState赋值,但会导致另一个问题。 只是不要使其无边界,无论如何边界不可见。 The native Windows MDI implementation cannot deal with borderless MDI child windows. Unfortunately, Winforms forgets to enforce that restricti ...
-
也许这个示例MDI客户端表单代码提供灵感: unit Unit3; interface uses Windows, Messages, Controls, Forms; type TForm3 = class(TForm) private FSizing: Boolean; procedure WMNCMouseLeave(var Message: TMessage); message WM_NCMOUSELEAVE; procedure WMWindo ...