如何将Bash命令的输出分配给变量?(How to assign the output of a Bash command to a variable? [duplicate])
这个问题已经在这里有一个答案:
- 如何从Bash中的命令设置一个变量到输出? 12答案
将
pwd
命令的内容放入我将在稍后使用的shell变量中。这是我的shell代码(循环不停止):
#!/bin/bash pwd= `pwd` until [ $pwd = "/" ] do echo $pwd ls && cd .. && ls $pwd= `pwd` done
你能发现我的错吗?
This question already has an answer here:
I have a problem putting the content of
pwd
command into a shell variable that I'll use later.Here is my shell code (the loop doesn't stop):
#!/bin/bash pwd= `pwd` until [ $pwd = "/" ] do echo $pwd ls && cd .. && ls $pwd= `pwd` done
Could you spot my mistake, please?
原文:https://stackoverflow.com/questions/2314750
更新时间:2022-09-27 11:09
最满意答案
我喜欢返回一个新的集合实例。 这使得这些过滤方法可以链接(例如
boxes.byColor("red").bySize("L")
)。var Boxes = Backbone.Collection.extend({ model: Box, byColor: function (color) { filtered = this.filter(function (box) { return box.get("color") === color; }); return new Boxes(filtered); } }); var red_boxes = boxes.byColor("red")
I like returning a new instance of the collection. This makes these filtering methods chainable (
boxes.byColor("red").bySize("L")
, for example).var Boxes = Backbone.Collection.extend({ model: Box, byColor: function (color) { filtered = this.filter(function (box) { return box.get("color") === color; }); return new Boxes(filtered); } }); var red_boxes = boxes.byColor("red")
相关问答
更多-
回答你的问题: 可以扩展视图或集合以具有触发更改事件的属性,答案是否定的,是的。 不,你不能做view.set({attr: value})或collection.set({attr: value}) 但是,您可以通过扩展Backbone.Events来获取视图或集合触发事件。 YourView = Backbone.View.extend({}); _.extend(YourView, Backbone.Events); var view = new YourView(); view.bind('Sel ...
-
我喜欢返回一个新的集合实例。 这使得这些过滤方法可以链接(例如boxes.byColor("red").bySize("L") )。 var Boxes = Backbone.Collection.extend({ model: Box, byColor: function (color) { filtered = this.filter(function (box) { return box.get("color") === color; ...
-
您可以通过将集合中的Playlist转换为模型来解决问题。 如果您考虑这个问题, Playlist可能会有其他属性(例如名称),不能在集合中设置。 Playlists将是Playlist模型(而不是集合)的集合,它应该无错误地工作。 var Track = Backbone.Model.extend({ //trackdata }); var Playlist = Backbone.Model.extend({ model : Track }); var Playlists = Back ...
-
Backbone:如何从模型集合中保存模型的属性更改?(Backbone: How to save an attribute change of a model right from its collection?)[2022-08-02]
我总是喜欢做的一件事是避免这样的问题,即创建“列表视图”和“项目视图”,并在列表视图上呈现多个项目视图。 这允许我有两个单独的事件哈希:一个在项目视图级别,一个在列表视图级别。 这样做也很明显Backbone事件处理应该去哪里(项目视图如果我们专注于一个模型,列表视图,如果我们专注于集合)。 还要记住,Backbone集合将所有模型事件代理到它们自己的事件触发器,因此可以进行collection.on("change:someModelAttr") 。 所有这些回调都将获得受影响的模型。 The probl ... -
你也可以使用Underscore some (aka any ),它几乎与你的search函数相同,除了它使用函数参数作为它的谓词,而不是键/值: 如果列表中的任何值通过迭代器真相测试,则返回true。 如果找到了真实元素,则短路并停止遍历列表。 这个实现使用更直接一些: search: function (attribute, value) { return this.some(function(x) { return x.get(attribute) === value; ...
-
在Backbone中没有一种真正的方法来处理嵌套集合。 引用Backbone常见问题解答 : Backbone不包括对嵌套模型和集合的直接支持,或者“有很多”关联,因为在客户端有许多用于建模结构化数据的良好模式,Backbone应该为实现其中任何一个提供基础。 FAQ还提供了一种模式,并提供了Extensions,Plugins,Resources页面的链接,该页面链接到许多可用于处理嵌套模型和模型关系的库。 也就是说,我有时会遇到这样的问题: var Author = Backbone.Model.ext ...
-
Backbone collection的模型 - 对象结构不正确?(Backbone collection's models-object incorrect structure?)[2022-11-13]
您的服务器似乎正在返回嵌套在JSON响应中的tasks Array。 为了让Backbone知道如何正确解析JSON,您需要覆盖parse()方法并告诉它使用tasks数组作为模型的源。 var MyModel = Backbone.Model.extend({}); var MyCollection = Backbone.Collection.extend({ model: MyModel, parse: function(response) { ... -
骨干集合。(backbone collection. “load more” button)[2024-01-28]
我想说最好的办法就是使用同一个集合的2个实例。 其中包含所有模型的模型,以及其中包含可见模型的模型。 您可以将视图绑定到“可见”集合,当您单击加载更多时,只需将模型从完整集合复制到可见集合。 我不会为此编写代码,因为您的StartView需要一些重构,我会尝试使用您的视图执行以下操作: 从视图中删除你的collection.fetch和render调用,并将它们移动到一个控制你的应用程序的对象,设置你的视图等。这样的视图是一个非常愚蠢的对象,它知道它的DOM元素,它需要的集合渲染,这就是它。 不要使用fet ... -
您可以筛选出包含在数组中的状态的所有模型,然后获取此结果数组的长度: var numOfModels = collection.filter(function(model) { return array.indexOf(model.get('status')) !== -1; }).length; You could filter out all the models which has a status contained in the array, and then take the lengt ...
-
嗨,这里是可以过滤多种类型的代码,存储在数组中 var typesTofilter=[5,1,2];//array of type tobe search. var f2=friends.filter(function(o){ var accept=false; $(typesTofilter).each(function(i,val){ ...