关于bash:forfileinif?的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于-bash:./switch.sh:/bin/bash^M:badinterpreter:Nosuch
关于bash:for file in if?的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于-bash: ./switch.sh: /bin/bash^M: bad interpreter: No such file or directory、-bash: ./xxx.sh: /bin/bash^M: bad interpreter: No such file or directory、-bash: /etc/init.d/nginx: /bin/bash^M: bad interpreter: No such file or directory、ASP.NET Core MVC base64映像到IFormFile等相关知识的信息别忘了在本站进行查找喔。
本文目录一览:- bash:for file in if?
- -bash: ./switch.sh: /bin/bash^M: bad interpreter: No such file or directory
- -bash: ./xxx.sh: /bin/bash^M: bad interpreter: No such file or directory
- -bash: /etc/init.d/nginx: /bin/bash^M: bad interpreter: No such file or directory
- ASP.NET Core MVC base64映像到IFormFile
bash:for file in if?
for f in *.c; do echo "That $f is the best C code I have ever seen"; done
如果没有c文件,很乐意打印
That *.c is the best C code I have ever seen
这是不可取的.如果没有c文件,是否有一种优雅的方法来修复/表达我想完全跳过循环的事实?
解决方法
nullglob
选项.如果没有匹配,则扩展将为空.
shopt -s nullglob for f in *.c; do …
请注意,这是一个特定于bash的构造,它在普通sh下不起作用.
-bash: ./switch.sh: /bin/bash^M: bad interpreter: No such file or directory
问题:
偶然使用 windows 进行编写脚本。使用 wsl (windows subsystem for linux) 进行运行的时候,什么事情没有。但是当把脚本移植到远程服务器进行运行的时候,发现脚本执行出现了错误:-bash: ./switch.sh: /bin/bash^M: bad interpreter: No such file or directory 。一时间解决不了。理论上都使用wsl 执行过了,应该是没问题了。但是通过查找资料发现,确实是有问题:
思考:
应该是就是windows 中 CRLF 与 linux 或者Unix类系统中的 LF 之间的区别。这段时间听说,window 即将更正CRLF 这个换行。想必到时应该就没有上述的问题了。同时我们也可以证明发现。在windows subsystem for linux 中,其是兼容windows的 CRLF 的这种格式的。
解决方法:
1. 使用 vim/vi 中的 命令
:set ff=unix
2. 使用 bash 中的dos2unix 命令,来进行文件格式转换。这个操作可以在服务器上,也可以使用windows subsystem linux 完成。 如果系统中没有 dos2unix 工具,那么你可能需要使用 yum / apt / dnf / pacman 之类的 包管理软件,进行安装一下了。
DESKTOP-05DDFQ6# dos2unix runmake.sh
dos2unix: converting file runmake.sh to Unix format ...
转载请注明出处. 2018年5月13日
-bash: ./xxx.sh: /bin/bash^M: bad interpreter: No such file or directory
一些人喜欢用vim来写linux shell script, 但是, 有的人喜欢在Windows下用一些方便的编辑器(比如鼎鼎大名的Notepad++)写好, 然后拷贝文件到linux下, 结果呢, 在执行脚本a.sh的时候, 会出现如下问题:
什么原因呢, 我们有理由怀疑是文件格式问题? 我们用vim a.sh进入a.sh这个文件, 然后在底部模式下, 执行:set ff查看一下, 结果发现fileformat=dos, 看看, 果然是文件格式问题, 那怎么解决呢?
方法一:vim a.sh进入a.sh后, 在底部模式下, 执行:set fileformat=unix后执行:x或者:wq保存修改。 然后就可以执行./a.sh运行脚本了。(我亲自试过, 是ok的)
方法二:直接执行sed -i "s/\r//" a.sh来转化, 然后就可以执行./a.sh运行脚本了。(我亲自试过, 是ok的)
方法三:直接执行dos2unix a.sh来转化, 然后就可以执行./a.sh运行脚本了。(我的linux上执行dos2unix ./a.sh失败, 但是不要放弃啊, 加个busybox就可以了), 如下:
-bash: /etc/init.d/nginx: /bin/bash^M: bad interpreter: No such file or directory
-bash: /etc/init.d/nginx: /bin/bash^M:bad interpreter: No such file or directory
这个使为了弄 nginx 自启的,然后在官网找了个 shell 脚本发现不行啊。。。。。。
找啊找。。。。
解决
vi /etc/init.d/nginx
保持退出就行。。。
因为使复制的别人的脚本。。。。。。
所以在 Linux 中运行所以使 dos 格式的
ok,然后解决了
ASP.NET Core MVC base64映像到IFormFile
日Thnx
解决方法
If you’re trying to get a object/viewmodel that contains a Byte[]/base64,
i searched in hours for a solution but then i added extra parameter to my viewmodel
public class ProductAddVM { public int Id { get; set; } public Categories Category { get; set; } public decimal Vat { get; set; } public string Name { get; set; } public decimal Price { get; set; } public IFormFile Image { get; set; } public Byte[] ByteImage { get; set; } public string Description { get; set; } public bool? Available { get; set; } }
参数Image用于存储可能正如您所述在EDIT中上传的新图像.
而参数ByteImage是从数据库中获取旧图像.
The where you’re done editing you can convert the IFormFile to byte[] and save it in DataBase
I tried to use Mapper but it went wrong,this code is working 100% but i’m gonna make it look better
internal ProductAddVM GetProduct(int id) { var model = new Product(); model = Product.FirstOrDefault(p => p.Id == id); var viewmodel = new ProductAddVM(); viewmodel.Id = model.Id; viewmodel.Name = model.Name; viewmodel.Available = model.Available; viewmodel.Description = model.Description; viewmodel.Price = model.Price; viewmodel.Category = (Categories)model.Category; viewmodel.Vat = model.Vat; viewmodel.ByteImage = model.Image; return viewmodel; } internal void EditProduct(int id,ProductAddVM viewmodel,int userId) { var tempProduct = Product.FirstOrDefault(p => p.Id == id); tempProduct.Name = viewmodel.Name; tempProduct.Available = viewmodel.Available; tempProduct.Description = viewmodel.Description; tempProduct.Price = viewmodel.Price; tempProduct.Category =(int)viewmodel.Category; tempProduct.Vat = CalculateVat(viewmodel.Price,(int)viewmodel.Category); if (viewmodel.Image != null) { using (var memoryStream = new MemoryStream()) { viewmodel.Image.copyToAsync(memoryStream); tempProduct.Image = memoryStream.ToArray(); } } tempProduct.UserId = userId; tempProduct.User = User.FirstOrDefault(u => u.Id == userId); SaveChanges(); }
关于bash:for file in if?的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于-bash: ./switch.sh: /bin/bash^M: bad interpreter: No such file or directory、-bash: ./xxx.sh: /bin/bash^M: bad interpreter: No such file or directory、-bash: /etc/init.d/nginx: /bin/bash^M: bad interpreter: No such file or directory、ASP.NET Core MVC base64映像到IFormFile等相关知识的信息别忘了在本站进行查找喔。
本文标签: