首页 \ 问答 \ 将cURL输出分配给Bash中的变量(Assign output to variable in Bash)

将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
更新时间:2024-05-02 20:05

最满意答案

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;

Here's a simple example

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孩子,但是时间可能会混淆,在这种情况下,错误的表格最终可能会排在最前面。 这可能在启动时或加载或关闭文件时发生。 可能在父完成加载之前加载子表单,而父表单尚未最大化。 子表单可以在父表单中正确最大化,但随后父表单变大。 您可以通过在父级的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 ...

相关文章

更多

最新问答

更多
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的
  • SimplePie问题(SimplePie Problem)
  • 在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)
  • HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)
  • 为什么我会收到链接错误?(Why do I get a linker error?)
  • 如何正确定义析构函数(How to properly define destructor)
  • 垂直切换菜单打开第3级父级。(Vertical toggle menu 3rd level parent stay opened. jQuery)
  • 类型不匹配 - JavaScript(Type mismatch - JavaScript)
  • 为什么当我将模型传递给我的.Net MVC 4控制器操作时,它坚持在部分更新中使用它?(Why is it that when I pass a Model to my .Net MVC 4 Controller Action it insists on using it in the Partial Update?)
  • 在使用熊猫和statsmodels时拉取变量名称(Pulling variable names when using pandas and statsmodels)
  • 如何开启mysql计划事件
  • 检查数组的总和是否大于最大数,反之亦然javascript(checking if sum of array is greater than max number and vice versa javascript)
  • 使用OpenGL ES绘制轮廓(Drawing Outline with OpenGL ES)
  • java日历格式(java Calendar format)
  • Python PANDAS:将pandas / numpy转换为dask数据框/数组(Python PANDAS: Converting from pandas/numpy to dask dataframe/array)
  • 如何搜索附加在elasticsearch索引中的文档的内容(How to search a content of a document attached in elasticsearch index)
  • LinQ to Entities:做相反的查询(LinQ to Entities: Doing the opposite query)
  • 从ExtJs 4.1商店中删除记录时会触发哪些事件(Which events get fired when a record is removed from ExtJs 4.1 store)
  • 运行javascript后如何截取网页截图[关闭](How to take screenshot of a webpage after running javascript [closed])
  • 如何使用GlassFish打印完整的堆栈跟踪?(How can I print the full stack trace with GlassFish?)
  • 如何获取某个exe应用程序的出站HTTP请求?(how to get the outbound HTTP request of a certain exe application?)
  • 嗨,Android重叠背景片段和膨胀异常(Hi, Android overlapping background fragment and inflate exception)
  • Assimp详细说明typedef(Assimp elaborated type refers to typedef)
  • 初始化继承类中不同对象的列表(initialize list of different objects in inherited class)
  • 使用jquery ajax在gridview行中保存星级评分(Save star rating in a gridview row using jquery ajax)
  • Geoxml3 groundOverlay zIndex(Geoxml3 groundOverlay zIndex)