我想创建一个shell脚本,可以永久地更改我的Ubuntu的主机名.每当我使用该hostname New_hostname命令时,它会在我重新启动机器后返回到原始主机名.
我发现我可以永久改变它的唯一方法是修改文件/etc/hostname并保存.有没有办法只使用shell脚本才能做到这一点?我也有密码.
我将从Windows机器创建的.sh文件发送到linux,以便我可以在那里运行它.问题是我继续得到一个名为bad interpreter的错误.但是当我在linux机器上编写shell脚本时,它运行没有问题,即使它与从windows机器发送的代码具有相同的代码.经过我的调查,我发现windows machine .sh脚本是一个text/plain文件(使用文件-bi),另一个来自linux机器是text/x.shellscript.有没有办法将text/plain转换为text/x.shellscript?谢谢
这是脚本:
#!/bin/bash
date
sudo apt-get update
Run Code Online (Sandbox Code Playgroud)
我通过在仅包含的Linux框中执行另一个.sh文件尝试了一个解决方案
#!/bin/bash
Run Code Online (Sandbox Code Playgroud)
然后windows机器只发送一个包含测试命令的文件,如:
date
hostname
Run Code Online (Sandbox Code Playgroud)
然后我将文件从windows框附加到linux上
cat windows.sh >> linux.sh
Run Code Online (Sandbox Code Playgroud)
如果我运行linux.sh它不起作用.它说错误如:
./linuxh.sh: line 2 $'date\r':command not found
./linuxh.sh: line 2 $'hostname\r':command not found
Run Code Online (Sandbox Code Playgroud)
但是,如果我打开Linux.sh然后再次保存它而不做任何事情.有用
string[][] Chop = null;
string[] Line = null;
private void button1_Click(object sender, EventArgs e)
{
Line = textBox1.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); // Im succesfull at cutting the input per line and stores it per line in Line variable.
for(int x = 0;x < Line.Length; x++)
Chop[][x] = Line[x].Split(' ');
//I want the Chop to have an array of array of strings.
Run Code Online (Sandbox Code Playgroud) 我有两个字符串,即string1和string2.它们包含二进制数,我想用不同的操作来操作它们.
例如:
string string1 = "1000";
string string2 = "1011";
Run Code Online (Sandbox Code Playgroud)
如何添加/减去string1和string2,以便:
AnswerToAddtion = 10011 //1000 + 1011
AnswerToSubtratction = 1101 //1000-1011
Run Code Online (Sandbox Code Playgroud)